简体   繁体   English

如何在删除TableView中的行后修复画外音

[英]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. 我有2个部分的tableview。

  • The first section got a header of height = 0 and only one row of variable height. 第一部分得到一个高度= 0的标题,只有一行可变高度。
  • The second section got a header with fixed height with a button inside; 第二部分有一个固定高度的标题,里面有一个按钮; rows in this sections can be 'n'. 此部分中的行可以是'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. 相反,当您向上滚动时,vo会读取屏幕上可见的单元格,但会在其下方的单元格之前读取第一个部分的标题。

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 每个部分中的单元格具有: isAccessibilityElement = false

the accessibility element is the card inside the cell like this: accessibility元素是单元格内的卡片,如下所示:

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. 但是当变量isExpanded为false时,第一部分中行的高度设置为0而不是自动。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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