简体   繁体   中英

How to fix voiceover after deleting a row in a TableView

I've got some problems fixing voiceover after deleting a row. the structure is like this:

I've got a tableview with 2 sections.

  • The first section got a header of height = 0 and only one row of variable height.
  • The second section got a header with fixed height with a button inside; rows in this sections can be 'n'. When the user tap the button inside the header the cell in the first section is deleted or re-inserted according to the previous state.

In the normal 'state' with the cell expanded the voiceover works perfectly. When the user taps the button and delete the row in the first section the voiceover breaks. If I browse from top to bottom it's all ok. Instead when you scroll upwards the vo reads the cells visible on the screen but reads the header of the first section before the cells below it.

Insert and deleting is pretty simple:

let indexPath = IndexPath(row: 0, section: 0)
if isExpanded {
   if tableView.contentOffset.y <= 0 {
       tableView.insertRows(at: [indexPath], with: .automatic)
   } else {
       tableView.reloadData()
       tableView.scrollToRow(at: indexPath, at: .top, animated: true)
   }
} else {
   tableView.deleteRows(at: [indexPath], with: .automatic)
}

cells in each sections have: isAccessibilityElement = false

the accessibility element is the card inside the cell like this:

cardView.isAccessibilityElement = true
cardView.accessibilityTraits = .button

I would really appreciate your help, I have tried different solutions but none of them work. It's pretty much a headache!

Let me know if you need more info to solve this. Thank you.

Solved this by keeping always a row in the first section.

tableView.performBatchUpdates({
     tableView.deleteRows(at: [indexPath], with: .fade)
     tableView.insertRows(at: [indexPath], with: .fade)
}, completion: nil)

But when the variable isExpanded is false the height of the rows in first section is set to 0 instead of automatic.

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0 {
            return isExpanded ? UITableView.automaticDimension : 0
        }
        return UITableView.automaticDimension
    }

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