Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a subview to a custom viewForHeaderInSection breaks VoiceOver navigation

I have a UITableViewController and I am trying to customize the section headers to look more like plain text. I am finding that when I add a subview to the custom headerView (detailed below), it breaks VoiceOver header navigation.

For example: Say I have a table with three headers: Header1, Header2, Header3.

Without a custom implementation of the viewForHeaderInSection method I can switch the voiceover rotor to navigate by headings and everything works as intended.

When I implement the viewForHeaderInSection method in the following way I can move from Header1 to Header2 to Header3 and back up to Header2, but then voiceover loses all of the headers (saying "no headers found").

I've found the problem starts when I add the headerLabel as a subview to headerView. I have tried setting headerLabel to a hidden accessibility element so voiceover won't pick it up, but the problem persists.

- (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 why VoiceOver is reacting like this would be appreciated.

Thanks.

like image 257
ranonk Avatar asked Jan 30 '12 20:01

ranonk


1 Answers

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

I had custom UIView for section headers, and kept a pool of these in an array, and occationally reused them. This confused VoiceOvery completely, and going forward or backward did not always result in selecting the previous or the next cell as expected.

However, when I changed into creating a new UIView each time tableView:viewForHeaderInSection: was called, this navigation confusion of VoiceOver stopped, and all worked well. My header views are accessible (isAccessibleElement) and has a label set.

like image 53
claxclinton Avatar answered Sep 20 '22 16:09

claxclinton