Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set voiceover's focus on a specific table cell in uitableview (UIAccessibility)

I have a UITableView that I have scroll to the bottom as soon as the user adds another element/table cell to it. For the screen this works fine, because the user can see the cell they just added at the bottom of the table. But when running my app using VoiceOver, the first UITableCell to get focused and read is the top cell that's visible on the screen.

I want to set it so that the cell that gets focused and then read as soon as this UITableView appears is the very last cell in the table. How do I do this? It seems like it would be very simple but I can't figure it out.

Here's what I tried so far (in cellForRowAtIndexPath):

if (cellJustAdded && indexPath.row == [array count]-1) {
    cell.accessibilityElementIsFocused = YES; //obviously this does not work
}

but I don't think you can use accessibilityElementIsFocused like that.

like image 689
Ginny Avatar asked Dec 26 '11 23:12

Ginny


1 Answers

When you want VoiceOver to select a certain element you can post an accessibility notification using UIAccessibilityPostNotification( ... );.

Depending on if it's a major (complete screen) change or a minor (layout only) change you should post either

  • UIAccessibilityScreenChangedNotification (complete change)
  • UIAccessibilityLayoutChangedNotification (small change)

In both cases the optional argument is the element that VoiceOver should move to.

So after having added the new cell to your table view you would call

UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification,
                                yourNewCellThatShouldHaveFocus); 
like image 116
David Rönnqvist Avatar answered Oct 23 '22 21:10

David Rönnqvist