Original URL: http://blog.talisk.cn/blog/2015/09/01/uitableview-didselectrowatindexpath-cannot-be-called-tips/
As a common control that UITableView appears in many iOS apps, there is a problem with the recent development that nested other controls with interactive events in the custom cell, blocking the cell, leading to the inability to callback the didSelectRowAtIndexPath method and finally the solution.
Sentence plan
Set the properties of the control that may affect the tap event userInteractionEnabled to NO .
1
|
[self. ScrollView setuserinteractionenabled:NO];
|
Problem leads
In order to display more than one item in a cell, and in order to facilitate the paging process, it is UIScrollView more appropriate, as needed, can only be UIScrollView set to full size (scrollview size and cell size of the same), because scrollView It has events, so when you click on the cell, tableView didSelectRowAtIndexPath you can't respond.
Like Uiscrollview, the control that causes the problem, and UITableView UICollectionView UITextField so on, when the dimensions of the child view cover the entire cell, you will find that you cannot recall didSelectRowAtIndexPath . (Of course, if the sub-view can not completely cover the cell, click on the not covered part, or can be normal callback).
Principle
userInteractionEnabledis a Boolean value, when set to Yes, the control can receive interactive events, interactive events at the same location, and its parent control cannot receive interactive events. It is because of how iOS handles interactive events that it causes the cell to be unable to callback didSelectRowAtIndexPath . When this boolean value is true NO , the interaction event is handled by its parent view, and if the interaction cannot be handled by the root view, the interaction is discarded unless a view can handle the interaction.
Postscript
In fact, this is not the best solution, because, in many cases, we need both the parent view in response to the interaction event, and the child view to handle some interactive events, the solution directly to the interaction of the view of a stick killed. For example, we add a scrollview to the cell, and we want the callback when the user taps, didSelectRowAtIndexPath scrolling when swipe scrollView . So add a todo here: perfect solution "Child view and parent view handle different interactions separately".
"Go" custom UITableViewCell control blocking callback Didselectrowatindexpath workaround