1

I have a button inside of a UITableView. The UITableView was created in storyboard, but the button was created pragmatically. I get:

Unexpected exception occurred SLUIAElementInvalidException for reason: Element '<SLButton description:"Add Memberin">' does not exist.

when I try to "tap" the button element:

SLButton *addMemberButton = [SLButton elementWithAccessibilityLabel:@"Add Member"];
SLLog(@"%@", addMemberButton); // prints <SLButton description:"Add Member">
[addMemberButton tap];

I have the following code in viewDidLoad in the viewController:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.addMemberButton.isAccessibilityElement = YES;
    self.addMemberButton.accessibilityValue  = @"Add Member";
    self.addMemberButton.accessibilityTraits = UIAccessibilityTraitButton;
}

When I use the accessibility inspector, the button is accessible and has the label I created. I even tried turning off accessibility in the UITableView with:

self.tableView.isAccessibilityElement = NO;
self.tableView.accessibilityLabel = nil;

This made no difference. Any insights as to how to fix this would be greatly appreciated.

alaursen
  • 13
  • 2

1 Answers1

0

It looks like you're trying to match the button by label, but "Add Member" is actually the button's value.

SLButton *addMemberButton = [SLButton elementWithAccessibilityLabel:nil value:@"Add Member" traits:UIAccessibilityTraitButton];

should work instead, though I think it would be more appropriate to set "Add Member" as the label (see the description of accessibilityLabel vs. accessibilityValue here, as well as the guidelines here).

If "Add Member" is the button's title, you actually don't need to set any properties manually--buttons automatically derive their accessibility labels from their titles.

Jeffrey Wear
  • 1,155
  • 2
  • 12
  • 24