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

Source: Internet
Author: User

part of the code for registering gestures in Viewdidload is as follows: [CPP] View plaincopy UITapGestureRecognizer*onetap =[[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Hidekeyboard)] autorelease]; Onetap.Delegate=Self ; Onetap.numberoftouchesrequired=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*) The Indexpath does not execute. 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#pragmaMark-uigesturerecognizerdelegate-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldreceivetouch: (Uitouch *) Touch {//The class name of the view that outputs the clickNSLog (@"%@", Nsstringfromclass ([Touch.viewclass])); //if Uitableviewcellcontentview (that is, click Tableviewcell), the touch event is not intercepted    if([Nsstringfromclass ([Touch.viewclass]) Isequaltostring:@"Uitableviewcellcontentview"]) {          returnNO; }      returnYES; } debug again, this time didselectrowatindexpath response, solve the uitapgesturerecognizer gesture intercept Touch event problem! 

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.