After adding uitapgesturerecognizer gesture recognition in iOS, UITableView's didselectrowatindexpath fails

Source: Internet
Author: User

Problem: Using Addgesturerecognizer:onetap causes the Didselectrowatindexpath method to fail

Add a UIView, and then add table to this view, to this view using Addgesturerecognizer gesture click function, resulting in table Didselectrowatindexpath method invalidation.

Part of the code for registering gestures in Viewdidload is as follows:

[CPP]View Plaincopy
    1. [Self.view Addgesturerecognizer:onetap];

One of the Hidekeyboard methods is omitted, the basic is a few resignfirstresponder.

Then there was a strange phenomenon, click on the "Retrieve password" column when no response!!!


After debugging I found that the delegate method

-(void) TableView: (uitableview *) TableView Didselectrowatindexpath: (nsindexpath*) Indexpath not executed.

The visual reason is that UITapGestureRecognizer intercepted the touch event, causing the Didselectrowatindexpath method to fail to respond.


A workable workaround was found after reviewing the relevant documents: overriding the Uigesturerecognizerdelegate in the

-(BOOL) Gesturerecognizer: (uigesturerecognizer *) Gesturerecognizer Shouldreceivetouch: (Uitouch *) Touch method.

[CPP]View Plaincopy
    1. #pragma mark-uigesturerecognizerdelegateBOOL
    2. , Nsstringfromclass ([Touch.view class
    3. Ifclass]) {
    4. Returnreturn}

Debug again, this time Didselectrowatindexpath responds, solve the problem of UITapGestureRecognizer gesture intercept touch event!

After adding uitapgesturerecognizer gesture recognition in iOS, UITableView's didselectrowatindexpath fails

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.