0

Voiceover is typically implemented with accessibilityRole instance method. I was able to use it on a button for example

button.accessibilityRole = NSLocalizedString(@"Button", nil);

But when I use it on a NSTabViewItem,

NSTabViewItem *item0 = [NSTabViewItem tabViewItemWithViewController:self.tab0];
item0.acessibilityRole = NSLocalizedString(@"Tab 0",nil);

I get an error saying

Property 'accessibilityRole' not found on object of type 'NSTabViewItem *'

Edit: I also tried accessibilityLabel.

eh1412
  • 43
  • 1
  • 2
  • 8

2 Answers2

0

accessibilityLabel is usually called on Views, so I used it on NSView.

NSView * cellView = [NSView newAutoLayoutView];
cellView.accessibilityLabel = "label";
eh1412
  • 43
  • 1
  • 2
  • 8
0

A number of issues here.

  1. The primary problem is that accessibilityRole is a method which you override to return the role of your object. You can't set the role in the way you are attempting, you can only subclass an NSCell/NSView and return the appropriate string. However, you probably don't want to do that in this case because:
  2. You don't return a localized value from a view or cell's accessibilityRole property, you use one of the NSAccessibilityRole types. And more importantly:
  3. The role is only used to provide information about the kind of object VoiceOver has selected. In the case of tab views, the correct role for the tab view itself is NSAccessibilityTabGroupRole and each tab has NSRadioButtonRole and a subrole of NSAccessibilityTabButtonSubrole. This will happen for you automatically when you use an NSTabView. Note, you would never use a role of "Tab 0", which conflates the label with the role. And you don't need a label if the tab has a text title anyway, it would only be necessary if you had a tab with an icon for a title. And then the label would be something like "information" for an icon of ℹ️.
  4. You generally shouldn't override the accessibilityRole on a view/cell, but instead instantiate the right sort of object to begin with. For instance, instead of creating a button with a standard type of NSButtonTypeMomentaryPushIn and then overriding its role to be NSAccessibilityCheckBoxRole, you should just create a check box. Then the role/subrole/role description will be set correctly for you. In general, the only time you would want to override the accessibilityRole on a view is if you are rolling your own view from scratch.
  5. When setting accessbility attributes on a button or any other object with a cell, you shouldn't use the NSView (the NSButton instance). Instead, you need to use the NSCell (NSButtonCell, reached with button.cell). E.g. button.cell.accessibilityLabel = NSLocalizedString("Cancel", nil); While many AX attributes are passed through from the cell to the view, a few are not. Also, different accessibility technologies (VoiceControl, VoiceOver, SwitchControl) are more or less strict about this. You should always set things on the cell where appropriate to be compatible with widest range of AX technologies.
  6. The best way to work out what your app should do is to find analagous UI in an Apple product and explore the AX hierarchy using Accessibility Inspector.
Nick K9
  • 3,885
  • 1
  • 29
  • 62