Set accessibilityIdentifier on custom table section header view for UIAutomation

谁都会走 提交于 2019-12-06 09:19:20

You have to make sure that the view you're returning also responds to isAccessibilityElement with YES. I was able to solve this by experimenting with the core data books sample app that Apple provides.

I implemented a custom view like so:

static int counter = 0;

@interface MyView : UIView
@end

@implementation MyView

- (NSString *)accessibilityIdentifier
{
    return [NSString stringWithFormat:@"Custom Identifier %d", counter++];
}

- (BOOL)isAccessibilityElement
{
    return YES;
}

@end

And then I returned it to the table view delegate (which is the table view controller in this case):

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    MyView *v = [[MyView alloc] init];
    return v;
}

I think what's happening is that the accessibility infrastructure is looking at the header view and trying to grab the "identifier" of the first subview that says that it is indeed an accessibility element. So, in your case, the segmented control is returning YES to isAccessibilityElement so that is the trigger to the accessibility APIs that this identifier is the one that should be exposed.

So, the solution is to make sure that the UIView you are returning as the header returns YES to that method in addition to returning a custom identifier.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!