jawj
jawj

Reputation: 473

How can I avoid a crash when VoiceOver encounters UIPickerView as subview of UITableViewCell contentView?

In my app I have a UIPickerView as a subview of a table cell's contentView. I disable scrolling in the table view, and the arrangement works fine under normal circumstances. However, I've found that when VoiceOver (or the Accessibility Inspector) is turned on, the app crashes as soon as the picker is due to get focus.

The error is:

-[UITableViewCellAccessibilityElement numberOfComponents]: unrecognized selector sent to instance 0xc15dc70

What seems to be happening is that VoiceOver is sending messages presumably intended for the UIPickerView (or its own UIAccessibilityElement?) to the UITableViewAccessibilityElement instead.

When I patch UIAccessibilityElement with the following category...

@implementation UIAccessibilityElement (GMPatches)

- (NSInteger)numberOfComponents {
  return 0;
}

@end

... I eliminate the crash -- but now, unsurprisingly, VoiceOver cannot change the UIPickerView value.

And if I change it to the true value in this context...

@implementation UIAccessibilityElement (GMPatches)

- (NSInteger)numberOfComponents {
  return 1;
}

@end

... then VoiceOver sends the next misaddressed message, bringing everything down again:

-[UITableViewCellAccessibilityElement selectedRowInComponent:]: unrecognized selector sent to instance 0x1e97b0

I'm feeling fairly sure this is an iOS bug.

I've tried setting isAccessibilityElement = NO on the picker, the table cell and the table cell's content view, none of which helps.

I guess I might be able to expand the UIAccessibilityElement category above to forward various messages to its parent cell's child UIPickerView. But this feels like unpleasantly brittle hackery.

Any better ideas how I might work around this?

Upvotes: 1

Views: 978

Answers (2)

蒋业文
蒋业文

Reputation: 31

I had the same crash when I just set tableView.tableHeaderView = myUITextField and turn VoiceOver on in the system setting app. Problem has been solved now when I wrap myUITextField in a UIView and then assign it to tableView.tableHeaderView.

I believe this would be a bug in iOS 9 or later, for UITextField is also a sub class of UIView.

Upvotes: 1

grundprinzip
grundprinzip

Reputation: 2491

The issue you are facing has to be solved differently. You are trying to add the UIPicker to the UITableCell, but this is not possible. It looks like it is not possible to determine if you actually scrolled / picked the table cell or the UIPicker.

To overcome this issue, push another view to the table that includes the UIPicker.

Upvotes: 0

Related Questions