ios - Long press gesture recognizer on UIButton? -
i'm working on minesweeper game, want add together flag when user long tap on tile of gameboard. i've implemented code:
for every button in gameboard:
uilongpressgesturerecognizer *longpress = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(longpresstap:)]; longpress.minimumpressduration = 1.0f; [self.button addgesturerecognizer:longpress];
in self, method longpresstap:
- (void)longpresstap:(tile *)sender { if (sender.block.marking == marking_flagged) { // if flag mark blank tile, color defined gameboard sender.backgroundcolor = uicolorfromrgb(0x067ab5); sender.block.marking = marking_blank; self.flagcount++; } else{ // if it's not flag mark flag , set flag image tile [sender setbackgroundimage:[uiimage imagenamed:image_name_flag] forstate:uicontrolstatenormal]; sender.block.marking = marking_flagged; self.flagcount--; } }
and of course of study self uigesturerecognizerdelegate. when seek long press on tile, app crash , give error:
*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[uilongpressgesturerecognizer block]: unrecognized selector sent instance 0x8cf2b00'
what should do? i'm @ origin obj-c programming if can help me , explain did wrong i'll grateful.
- (void)showoptions:(uilongpressgesturerecognizer*)sender{ uibutton *btn = (uibutton*)sender.view; nslog(@"view tag %d",sender.view.tag); if (sender.state == uigesturerecognizerstateended) { } else if (sender.state == uigesturerecognizerstatebegan) { [self.bubbledelegate showoptionsformessage:btn]; }
}
ios objective-c uibutton long-press
No comments:
Post a Comment