iOS 9, UITableViewCellContentView on top of its subviews

In my app there is a view with a TableView, and the table has custom cells.


The cell is suppose to respond to tapping by going to a detail view. But in the cell, there is a button that has an update action and tapping on that button does not go to detail view. So there are two different actions in the cell.


This worked fine in iOS 8, but now that I updated one of my test devices to iOS 9 to test the app, the update action of the button does not work anymore.


The problem is that UITableViewCellContentView of the cell gets on top of every other subview (visible on the debug view hierarchy) of the cell thus preventing the tapping of the button. So now tapping both on the cell and on the button goes to detail view.


I did not find any solution to get the content view back in the behind of all other subviews. Also I find it strange that the content view is actually getting on top where it should not be.


I wonder if anyone else is experiencing this isssue?

Accepted Reply

There should normally be no other views (that you care about) besides the content view. You should add your custom subviews to the content view, not to the cell.

Replies

Although I still don't understand why the content view is on top of other subviews (and added to the cell's view hierarchy on iOS 9 and not on iOS 8), I solved the issue by bringing to front all other subviews.


It would still be nice to know if others experience the same issue and to understand if this is a bug or if something has changed for how a table cell's contents are rendered.

There should normally be no other views (that you care about) besides the content view. You should add your custom subviews to the content view, not to the cell.

The cell has a xib file and the custom subviews are added in the designer to the content view, I don't add them programmatically. So they are in correct order.


But you were partly right. 🙂


The xib was created as a UIView. Which means it did not have any content view. iOS 8 being probably more flexible, it allowed it to be used as a cell and did not put any content view on runtime.


Now, iOS 9, I think correctly, puts a content view to a table cell, even though you use a custom cell/xib. which had another structure. The content view being added after the custom cell, it was on top of it.


Now I changed the custom cell to be a table cell and the hierarchy is correct.


So iOS 9 is more strict and demands that we use the correct view where it is due 🙂


Thanks for the answer junkpile.