Shilpi
Shilpi

Reputation: 508

Turning off Voice-over focus for a cell in table view and not for others

The first cell in my table view is a dummy cell and thus, when Voice-over mode is ON, I want to skip that cell so that the focus does not come to that control and thus, none of its traits are spoken by the Voice over. I wrote the code pasted below to acheive the same, thinking that isAccessibilityElement alone is sufficient for this. But it seems that is not the case. Even though this element i said to be non-accessible in the code, still its getting focus by right/left flicks in Voice-over mode. Any idea as to how this can be achieved?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
....
     UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
     if(indexPath.row == 0)
     {
          cell.isAccessibilityElement = 0;
     }
}

Upvotes: 4

Views: 4829

Answers (4)

Arie Peretz
Arie Peretz

Reputation: 9

Just override the cell's function accessibilityElementCount like this:

Swift 4.2:

override func accessibilityElementCount() -> Int {
   return 0
}

Upvotes: 1

Joseph Lord
Joseph Lord

Reputation: 6504

The current way to do this seems to be setting accessibilityElementsHidden on the cell to true/YES (depending on whether using Swift or Obj-C.

Seems cleaner than other answers proposed and seems effective in my very brief testing.

Upvotes: 3

JP Hribovsek
JP Hribovsek

Reputation: 6707

use some cutom cell, and within that cell definition implement this:

- (NSInteger)accessibilityElementCount {
    NSIndexPath *indexPath = [(UITableView *)self.superview indexPathForCell: self];
    if(indexPath.row==0){
        return 0;
    }
    else{
        return 1;
    }
}

Upvotes: 2

Jared
Jared

Reputation: 39913

It’s not ideal but could you only display the cell when VoiceOver is not activated? You can use the

UIAccessibilityIsVoiceOverRunning()

Function to see if VoiceOver is on when your app loads, and register the

@selector(voiceOverStatusChanged)

Notification so you can be informed if the user enables or disables voiceover. For more on this see the following blog post. < http://useyourloaf.com/blog/2012/05/14/detecting-voiceover-status-changes.html>

Upvotes: 1

Related Questions