Re: Need help setting up accessibility link from source-view to (subview of) detail-view programmatically
Re: Need help setting up accessibility link from source-view to (subview of) detail-view programmatically
- Subject: Re: Need help setting up accessibility link from source-view to (subview of) detail-view programmatically
- From: Mike Engber <email@hidden>
- Date: Fri, 25 May 2012 09:51:32 -0700
On May 25, 2012, at 3:22 AM, Motti Shneor wrote:
> Maybe I got something wrong here?
>
> - (void)outlineViewSelectionDidChange:(NSNotification *)notification {
> id newSelectedItem = [self selectedSourceViewItem];
> [self updateDetailViewForItem:newSelectedItem];
>
> // Set up Accessibility link from selected item to its detail-view's initial responder.
> NSView *detailInitialResponder = [self.detailViewController initialFirstResponder];
> if (detailInitialResponder != nil) {
> NSMutableArray *accessibilityLinks = [NSArray arrayWithObjects:detailInitialResponder, nil];
> id accessibilityItem = [[_sourceView tableColumnWithIdentifier:@"Label"] dataCellForRow:[_sourceView rowForItem:item]];
> BOOL linkIsSet = [accessibilityItem accessibilitySetOverrideValue:accessibilityLinks forAttribute:NSAccessibilityLinkedUIElementsAttribute];
> }
First, are you running with NSAccessibilityDebugLogLevel 1 and looking for spewage?
The thing that often goes wrong with attempts to use accessibilitySetOverrideValue is that you don't message the "right" object. By "right" I mean the actual object that corresponds to UI Element being exposed.
E.g. For many controls, the right object is the underlying cell, not the NSControl. In this case the proper soln is to us NSAccessibilityUnignoredDescendant on the NSControl to get back the object you need to message. For this case, NSAccessibilityDebugLogLevel would warn you about trying to set an attribute on an ignored UI Element.
Other cases can be trickier. E.g. the segments in a segmented control. There are no Cocoa object to represent them - they are just referenced by index. This means there's no object to use with NSAccessibilityUnignoredDescendant. Below is some code that handles this. The thing to note is that it uses the accessibility protocol to get the "right" object.
I'm going to guess that in your case you need to do something similar. I.e. use the accessibility protocol to get the columns (via NSAccessibilityRowsAttribute) and pick the row out of there.
I'm just guessing here. I haven't actually tried this case out.
Also, if the row number changes (e.g. some item is added or deleted) you may need to redo these links. I think these attribute may be keyed off the row number - at least in old style table views. If you switch to view based table view things might work differently - hopefully better.
-ME
---
void SetSegmentDescriptions(NSSegmentedControl *control, NSString *firstDescription, ...)
{
// Use NSAccessibilityUnignoredDescendant to be sure we start with the correct object.
id segmentElement = NSAccessibilityUnignoredDescendant(control);
// Use the accessibility protocol to get the children.
NSArray *segments = [segmentElement accessibilityAttributeValue:NSAccessibilityChildrenAttribute];
va_list args;
va_start(args, firstDescription);
id segment;
NSString *description = firstDescription;
NSEnumerator *e = [segments objectEnumerator];
while ((segment = [e nextObject])) {
if (description != nil) {
[segment accessibilitySetOverrideValue:description forAttribute:NSAccessibilityDescriptionAttribute];
} else {
// Exit loop if we run out of descriptions.
break;
}
description = va_arg(args, id);
}
va_end(args);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden