Adding a subtitle to a custom viewForHeaderInSection interrupts VoiceOver navigation

I have a UITableViewController and I'm trying to customize the section headers to look more like plain text. I find that when I add a subview to a custom header (described in detail below), it disrupts the navigation of the VoiceOver headers.

For example: Let's say I have a table with three headers: Header1, Header2, Header3.

Without a custom implementation of the viewForHeaderInSection method, I can switch the voice transmission rotor to navigate the headers, and everything works as intended.

When I implement the viewForHeaderInSection method as follows, I can move from Header1 to Header2 to Header3 and back to Header2, but then the scoring loses all the headers (saying “no headers found”).

I found that the problem starts when I add the Label header as a subview to the headerView. I tried setting headerLabel to a hidden accessibility element, so the voice acting will not pick it up, but the problem will not go away.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.frame.size.width,30)]; UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, headerView.frame.size.width-120.0, headerView.frame.size.height)]; headerLabel.textAlignment = UITextAlignmentLeft; headerLabel.font = [UIFont boldSystemFontOfSize:22]; headerLabel.text = [headersArray objectAtIndex:section]; headerLabel.backgroundColor = [UIColor clearColor]; [headerView addSubview:headerLabel]; return headerView; } 

Any ideas that VoiceOver reacts to will be appreciated.

Thanks.

+6
source share
2 answers

This is unlikely to be the answer to the original problem, but I just worked on a similar problem.

I had a custom UIView for section headers, and it contained them in an array and periodically reused them. This confused VoiceOvery completely, and moving forward or backward did not always result in the selection of the previous or next cell, as expected.

However, when I changed my mind about creating a new UIView every time tableView: viewForHeaderInSection: is called, this VoiceOver navigation confusion stopped and everything worked fine. My headers are accessible (isAccessibleElement) and have a set of labels.

+1
source

I worked on a similar problem

 headerLabel.accessibilityTraits = [.header] 

(Swift code)

0
source

Source: https://habr.com/ru/post/907264/


All Articles