自定义UITableViewCell与UIAccessibility元素有关 [英] Custom UITableViewCell trouble with UIAccessibility elements

查看:656
本文介绍了自定义UITableViewCell与UIAccessibility元素有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我尝试什么,我都无法保持我的自定义UITableViewCell在UIAccessiblity的默认规则下应该。我不希望这个单元格像一个辅助功能容器(本身),所以遵循这个指南我应该能够访问所有子视图,对吧?!它说要使每个元素单独访问,并确保单元本身不可访问。

No matter what I try, I can't keep my custom UITableViewCell from acting like it should under the default rules for UIAccessiblity. I don't want this cell to act like an accessibility container (per se), so following this guide I should be able to make all of my subviews accessible, right?! It says to make each element accessible separately and make sure the cell itself is not accessible.

- (BOOL)isAccessibilityElement
{
    return NO;
}

- (NSString *)accessibilityLabel
{
    return nil;
}

- (NSInteger)accessibilityElementCount
{
    return 0;
}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier //cells use this reusage stuff
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) 
    {
        [self setIsAccessibilityElement:NO];
        sub1 = [[UILabel alloc] initWithFrame:CGRectMake(0,0,1,1)];
        [sub1 setAccessibilityLanguage:@"es"];
        [sub1 setIsAccessibilityElement:YES];
        [sub1 setAccessibilityLabel:sub1.text]

        sub2 = [[UILabel alloc] initWithFrame:CGRectMake(0,0,1,1)];
        [sub2 setAccessibilityLanguage:@"es"];
        [sub2 setIsAccessibilityElement:YES];
        [sub2 setAccessibilityLabel:sub2.text]

语音系统读取内容即使我试图阻止这种行为,整个细胞也会同时出现。我可以说

The voice over system reads the contents of the whole cell all at once, even though I'm trying to stop that behavior. I could say

        [sub2 setIsAccessibilityElement:NO];

但这会使这个元素完全不可读。我想保持它的可读性,但不要将整个单元格视为容器(并假设为英语)。在这方面似乎没有很多信息,所以至少我想记录它。

but that would would make this element entirely unreadable. I want to keep it readable, but not have the whole cell be treated like a container (and assumed to be the English language). There does not appear to be a lot of information out there on this, so at the very least I'd like to document it.

推荐答案

如果您有2个单独的元素( sub1 sub2 ),你可以覆盖 UIAccessibilityContainer 非正式协议的方法。

If you have 2 separate elements (sub1 and sub2), you could override methods of the UIAccessibilityContainer informal protocol.

- (NSInteger)accessibilityElementCount {
    return 2;
}

- (id)accessibilityElementAtIndex:(NSInteger)index {
    if (index == 0) {
        return sub1;
    } else if (index == 1) {
        return sub2;
    }
    return nil;
}

- (NSInteger)indexOfAccessibilityElement:(id)element {
    if (element == sub1) {
        return 0;
    } else if (element == sub2) {
        return 1;
    }
    return NSNotFound;
}

这篇关于自定义UITableViewCell与UIAccessibility元素有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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