ios - Adding UILongPressGestureRecognizer to UIButton inside custom UITableViewCell -


i have custom cell various iboutlets, on 1 button want add uilongpressgesturerecognizer long press gestures. here code (btw outlets connected correctly , ibaction method of button called correctly):

mycustomcell.h  @interface mycustomcell : uitableviewcell @property (strong, nonatomic) iboutlet uibutton *mybutton; @property (strong, nonatomic) uilongpressgesturerecognizer *longpressgesturerecognizer; @end  mycustomcell.m  - (void)awakefromnib {     // initialization code     self.longpressgesturerecognizer = nil; }  myviewcontroller.m  #import mycustomcell.h  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *identifier = @"mycell";     mycustomcell *cell = [tableview dequeuereusablecellwithidentifier:identifier forindexpath:indexpath];     if (!cell){         cell = [[mycustomcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:identifier];     }      cell.longpressgesturerecognizer = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(handlelongpressgestures:)];     cell.longpressgesturerecognizer.minimumpressduration = 1.0f;     cell.longpressgesturerecognizer.allowablemovement = 300.0f;     [cell.mybutton addgesturerecognizer:cell.longpressgesturerecognizer]; }  - (void)handlelongpressgestures:(uigesturerecognizer *)recognizer {     if ([recognizer.view iskindofclass:[uibutton class]]){         if (recognizer.state == uigesturerecognizerstatebegan){             nslog(@"long press began");         } else if (recognizer.state = uigesturerecognizerstateended){             nslog(@"long press ended");         }     } } 

the problem handlelongpressgestures: method never called.

the longpressgesturerecognizer should property on controller , not view(mycustomcell). move property on myviewcontroller , try again. guess weird happening when queues , dequeues mycustomcell.

objects(cells) reuse should lightweight. in case, longpressgesturerecognizer's target view controller , nasty.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -