简体   繁体   中英

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

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

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.

Just override the cell's function accessibilityElementCount like this:

Swift 4.2:

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

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 >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM