"Go" custom UITableViewCell control blocking callback Didselectrowatindexpath workaround

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.