ios - Error with customized button -
i have error:
2013-08-01 01:09:18.433 vstuphelper[28332:11303] -[vhmasterviewcontroller popviewcontroller:]: unrecognized selector sent instance 0x7566410 2013-08-01 01:09:18.434 vstuphelper[28332:11303] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[vhmasterviewcontroller popviewcontroller:]:
here code:
uibutton *bt=[uibutton buttonwithtype:uibuttontypecustom]; [bt setframe:cgrectmake(0, 0, 50, 30)]; [bt setimage:[uiimage imagenamed:@"menu.png"] forstate:uicontrolstatenormal]; [bt addtarget:self action:@selector(popviewcontroller:) forcontrolevents:uicontroleventtouchupinside]; uibarbuttonitem *leftbutton=[[uibarbuttonitem alloc] initwithcustomview:bt]; self.navigationitem.leftbarbuttonitem=leftbutton; self.navigationitem.leftbarbuttonitem.target = self.revealviewcontroller; self.navigationitem.leftbarbuttonitem.action = @selector(revealtoggle:);
i'm not @ english, apologize if i'm hard understand.
you have several problems:
1) calling popviewcontroller:
on asssume uiviewcontroller
subclass, when should calling on uinavigationcontroller
.
2) popviewcontroller:
takes bool value whether animate transition. action, gets passed sender default.
3) reassign target , action button (but these don't called when create uibarbuttonitem
using initwithcustomview:
initializer: see docs).
how fix this:
1) call method create button handler:
uibutton *bt=[uibutton buttonwithtype:uibuttontypecustom]; [bt setframe:cgrectmake(0, 0, 50, 30)]; [bt setimage:[uiimage imagenamed:@"menu.png"] forstate:uicontrolstatenormal]; [bt addtarget:self action:@selector(buttontouched:) forcontrolevents:uicontroleventtouchupinside]; uibarbuttonitem *leftbutton=[[uibarbuttonitem alloc] initwithcustomview:bt]; self.navigationitem.leftbarbuttonitem=leftbutton;
2) in method, pop view controller, or whatever want do:
- (void)buttontouched:(id)sender { [self.navigationcontroller popviewcontroller:yes]; //or assigned button action: [self.revealviewcontroller revealtoggle:(not sure you're supposed have here)]; }
Comments
Post a Comment