在UIAutomation的自定义表部分标题视图上设置accessibilityIdentifier [英] Set accessibilityIdentifier on custom table section header view for UIAutomation

查看:143
本文介绍了在UIAutomation的自定义表部分标题视图上设置accessibilityIdentifier的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在UITableView中的自定义节标题视图上设置辅助功能标识符?

How does one set an accessibility identifier on a custom section header view in a UITableView?

对于背景,因为在UIAutomation中记录表视图的元素树会生成与表组元素(UIATableGroup)混合的表单元格(UIATableCell实例)的平面列表,能够识别组使得更容易识别属于这些组的单元格(因为它们按顺序返回)。

For background, since logging the element tree of a table view inside UIAutomation produces a flat list of table cells (UIATableCell instances) intermingled with table group elements (UIATableGroup), being able to identify groups makes it easier to identify the cells that belong to those groups (since they are returned in order).

如果我在作为节头视图返回的自定义视图上显式设置了accessibilityIdentifier,我可以确认在该视图上确实设置了accessibilityIdentifier属性。

If I set an accessibilityIdentifier explicitly on a custom view that gets returned as a section header view, I can confirm that the accessibilityIdentifier property is indeed set on that view.

这是提供自定义部分标题视图的方法(当然,它实际显示在我的实际表格视图中):

Here's that method that feeds the custom section header view (which does show up in my actual table view, of course):

 - (UIView *)tableView:(UITableView *)tableView 
viewForHeaderInSection:(NSInteger)sectionNumber
{
    UIView *headerView = [self someMethodToRetrieveHeaderView];

    // This line is logging that indeed, the accessibility identifier is set.
    NSLog(@"Header view accessibility identifier is: '%@' for section number: %d",
     headerView.accessibilityIdentifier, sectionNumber);         
    return headerView;
}

问题变成了当我发出 logElementTree时( )在我的UIAutomation测试中使用JavaScript调用此表视图,它返回一个UIATableGroup元素,其名称派生自该节头视图内的文本内容(即回退到UIAccessibilityLabel启发式)。因为该节头中有一个分段控件,所以我得到的accessibilityLabel值不一致。因此,我希望绕过所有这些并分配一个显式标识符。

The problem becomes that when I issue a logElementTree() call in JavaScript in my UIAutomation test against this table view, it gives me back a UIATableGroup element that has a name derived from the textual content inside that section header view (i.e. falling back to UIAccessibilityLabel heuristics). Because that section header has a segmented control in it, I get inconsistent accessibilityLabel values. Hence, my desire to bypass all of that and assign an explicit identifier.

如何强制我自己的显式accessibilityIdentifier显示为UIATableGroup的name属性?

How do I force my own explicit accessibilityIdentifier to show up as the UIATableGroup's name property instead?

推荐答案

您必须确保您要返回的视图也响应 isAccessibilityElement 使用 YES 。我能够通过试验核心数据书来解决这个问题/ a> Apple提供的示例应用程序。

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;
}

我认为正在发生的事情是可访问性基础设施正在查看标题视图和试图抓住第一个子视图的标识符,它说它确实是一个可访问性元素。因此,在您的情况下,分段控件将 YES 返回到 isAccessibilityElement ,这是可访问性API的触发器这个标识符是应该公开的标识符。

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.

因此,解决方案是确保 UIView 你正在返回,因为标题返回 YES 除了返回自定义标识符之外。

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.

这篇关于在UIAutomation的自定义表部分标题视图上设置accessibilityIdentifier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆