UIAccessibility in gridView - doesn't see new cells

ε祈祈猫儿з 提交于 2019-12-12 02:19:59

问题


In my project I have tableView, as a row there is a custom UITableViewCell, that has one of it property - GMGridView (its similar to a UICollectionView), it has its delegate methods:

- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index {
GMGridViewCell *cell = [gridView dequeueReusableCell];

    if (!cell)
    {
        cell = [[GMGridViewCell alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
        cell.contentView = [[GridViewContentView alloc] initWithFrame:cell.frame style:GridViewStyleNews];
     }
    Item *feed = _contentArray[index];
       GridViewContentView *contentView = (GridViewContentView *)cell.contentView;
           contentView.textLabel.text = feed.textLabel;
    [contentView.imageView setURL:[NSURL URLWithString:feed.imageLink] withPreset:self.preset];
    cell.contentView = contentView;
    NSLog(@"Address index %d - %p:", index, cell);
        return cell;
}

At this stage - created custom contentView -GridViewContentView and is identities as cells contentView.

This custom content view is defined as Accessible inside of it there are next methods:

 - (BOOL)isAccessibilityElement {
    return YES;
}

- (NSString *)accessibilityLabel {
    return [NSString stringWithFormat:@"%p, %@", self.superview, self.textLabel.text];
}

In my case I have 19 items in GridView.

So when the tableView is loaded on iPad(in landscape) created 6 items they are inserted into NSArray inside of GridView:

2016-08-07 17:04:39.626 DummyAccessibility[2785:230602] Address index 0 - 0x7a0162e0:
2016-08-07 17:04:39.632 DummyAccessibility[2785:230602] Address index 1 - 0x797390e0:
2016-08-07 17:04:39.633 DummyAccessibility[2785:230602] Address index 2 - 0x79643db0:
2016-08-07 17:04:39.639 DummyAccessibility[2785:230602] Address index 3 - 0x7a013290:
2016-08-07 17:04:39.640 DummyAccessibility[2785:230602] Address index 4 - 0x7a0114f0:
2016-08-07 17:04:39.641 DummyAccessibility[2785:230602] Address index 5 - 0x7965ef30:

and Voice over tells correct text - that belongs to taped item. But When I scroll - additionally created next 2 items (6 and 7) , and the first 2 - is reused for items (8 and 9). new items:

2016-08-07 17:04:59.961 DummyAccessibility[2785:230602] Address index 6 - 0x79674ac0:
2016-08-07 17:05:00.366 DummyAccessibility[2785:230602] Address index 7 - 0x7a074f20:

reused items:

2016-08-07 17:05:00.982 DummyAccessibility[2785:230602] Address index 8 - 0x7a0162e0:
2016-08-07 17:05:05.704 DummyAccessibility[2785:230602] Address index 9 - 0x797390e0:

After debugging I identified that these newly items are never accepted by UIAccessibility. When I try to tap on it - VoiceOver tells - is redirected inside of the cell (number 5) and takes the textValue from it. So when I tries to tap on the reused items - it tells correct (reused textInfo). Such a situation (with these new items keeps the even when they are also reused). I can't understand why it is like that.

I spend a lot of time with it, but can't understand why it works like that. I would really appreciate any idea.

Thanks a lot in advance.


回答1:


I found the solution on the base of Sean Howell answer here iOS Accessibility for CollectionView in a TableViewCell

So I added additional property - UIView in my custom tableViewCell,

and then added into it -in my case - GMGridView.

    self.trickView = [[UIView alloc]initWithFrame:self.bounds];
    self.trickView.backgroundColor = [UIColor clearColor];
    self.trickView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    _trickView.accessibilityElements = @[gmGridView];
    [self.contentView addSubview:_trickView];
    [self.gridView removeFromSuperview];
    self.gridView = nil;
    self.gridView = gmGridView;
    [self.trickView addSubview:gmGridView];


来源:https://stackoverflow.com/questions/38814980/uiaccessibility-in-gridview-doesnt-see-new-cells

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