Refresh cell voice items by recharging cell (s)
After reading the UITableView that controls Accessibility elements and observing applications that have similar features, I realized that TableView should update its availability information when loading or reloading a cell. I tried to force the cell to reload after changing its accessibility properties, and this solved the problem. VoiceOver information has been updated.
The following is an example of code that runs when the corresponding cell is used. In addition, it can be triggered when any other event requires updating VoiceOver elements.
// Make changes to accessibility properties such as cell.isAccessibilityElement = false cell.accessibilityElementsHidden = true // reloadRows() allows VoiceOver to update its element list for the related cell(s) // "indexPath" is for the desired row // reloadRows() expects an array of IndexPaths so an array of one is created inline tableView.reloadRows(at: [indexPath], with: .automatic) // Calling UIAccessibilityPostNotification() is not necessary to realize the VoiceOver changes in the TableViewCell
Background
I struggled with this problem for a while before finding a solution. In my case, TableView cells are created in code. It has no storyboards or feathers. However, this solution should work no matter how the TableView was created.
I have custom, subclassed TableView cells with view hierarchies embedded in the code and added as a subspecies of the UITableViewCell contentView content. I suggested that I could change the isAccessibilityElement and / or accessibilityElementsHidden properties for various subzones and call UIAccessibilityPostNotification() to implement VoiceOver changes, as was done outside of the TableView. These changes were not recognized by VoiceOver, only the accessibility state in which the cell was when it was loaded was recognized.
For the cell I fought with, the height is dynamically changed to place the DatePicker, which is displayed and hidden when I click on the cell. I want the DatePicker to be visible to VoiceOver when it is displayed on the screen. I try not to reload TableView, sections or rows to make dynamic changes, if at all possible. If I have to reload, I try to make it as isolated as possible (reload one cell or one section, not the entire TableView). In this case, I did not need to reload everything so that the cell expanded to show DatePicker, so I did not have to overload the cell for availability updates.
More info: UIAccessibility API link on Apple website
source share