objective c - Custom gesture not sending action message -
i have created uigesturerecognizer subclass called longpressgesturerecognizer simulate long press gesture. (yes, know concrete subclass exists, i'm learning objective-c , experimenting bit.)
i have overridden following methods :
- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { self.state = uigesturerecognizerstatepossible; [self performselector:@selector(setstate:) withobject:[nsnumber numberwithint:uigesturerecognizerstaterecognized] afterdelay:2]; } - (void)touchescancelled:(nsset *)touches withevent:(uievent *)event { [nsobject cancelpreviousperformrequestswithtarget:self]; self.state = uigesturerecognizerstatecancelled; } - (void)touchesended:(nsset *)touches withevent:(uievent *)event { [nsobject cancelpreviousperformrequestswithtarget:self]; self.state = uigesturerecognizerstatefailed; } and in view controller property recognizer store gesture recogniser, have following code:
- (longpressgesturerecognizer *)recognizer { if (!_recognizer) { _recognizer = [[longpressgesturerecognizer alloc] init]; } return _recognizer; } - (void)viewdidload { [super viewdidload]; [self.recognizer addtarget:self action:@selector(log:)]; [self.view addgesturerecognizer:self.recognizer]; } - (ibaction)log:(longpressgesturerecognizer *)recognizer { //blah blah blah } my problem log: not getting called @ all... logging uigesturerecogniserstates in console, know gesture recogniser working expected far states concerned...
what doing wrong here?
there may other issues well, can tell -performselector:withobject:afterdelay: call isn't going work way you're hoping; you'll end passing pointer nsnumber object instead of int, state set kind of junk value. create method self.state = uigesturerecognizerstaterecognized , call instead.
Comments
Post a Comment