objective c - iOS- UITapGestureRecognizer Gives EXC_BAD_ACCESS -
i want add together click event in custom header class. next code. when click on header area gives exc_bad_access.
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { uitapgesturerecognizer *singlefingertap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handlesingletap:)]; [self.view addgesturerecognizer:singlefingertap]; } homecoming self; } - (void)handlesingletap:(uitapgesturerecognizer *)recognizer { cgpoint location = [recognizer locationinview:[recognizer.view superview]]; //do stuff here... } - (void)viewdidload { [super viewdidload]; // additional setup after loading view nib. } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. }
if custom header class subclass of uiview
means utilize self
instead of self.view
uitapgesturerecognizer *taprecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handlesingletap:)]; taprecognizer.numberoftapsrequired = 1; [self.view addgesturerecognizer:taprecognizer]; - (void)handlesingletap:(uitapgesturerecognizer *)recognizer { cgpoint location = [recognizer locationinview:[recognizer.view superview]]; //do stuff here... }
ios objective-c exc-bad-access
No comments:
Post a Comment