ios - Tapping UIButton that's a subview of UIView -
ios - Tapping UIButton that's a subview of UIView -
i'm having problem capturing taps on uibutton
that's subview of uiview
. here's how code setup:
// in myclass.m @interface myclass () @property (nonatomic, retain) uibutton *mybutton; @end @implementation myclass @synthesize mybutton; - (void) buttontapped:(id) sender { nslog(@"button tapped!"); } - (id) initwithframe:(cgrect)frame { if (!(self = [super initwithframe:cgrectzero])) homecoming nil; mybutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; [mybutton setimage:[uiimage imagenamed:@"image.png"] forstate:uicontrolstatenormal]; [mybutton addtarget:self action:@selector(buttontapped:) forcontrolevents:uicontroleventtouchupinside]; mybutton.exclusivetouch = yes; mybutton.frame = cgrectmake(100, 100, 100, 100); [self addsubview:mybutton]; homecoming self; } - (void) dealloc { [mybutton release]; [super dealloc]; } @end
the button appears in view. button color changes momentarily when tap it. selector buttontapped:
never called. any thought why?
how can verify buttontapped:
indeed target of mybutton?
you verify current class target logging r
nslog(@"actions target %@",[mybutton actionsfortarget:self forcontrolevent:uicontroleventtouchupinside]);
however, added code test project (single view template) , buttontapped:
method worked.
- (void) buttontapped:(id) sender { nslog(@"button tapped!"); } - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { self.window = [[[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]] autorelease]; self.window.backgroundcolor = [uicolor whitecolor]; [self.window makekeyandvisible]; self.viewcontroller = [[[viewcontroller alloc] initwithnibname:@"viewcontroller" bundle:nil] autorelease]; self.window.rootviewcontroller = self.viewcontroller; uibutton * mybutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; [mybutton setimage:[uiimage imagenamed:@"image.png"] forstate:uicontrolstatenormal]; [mybutton addtarget:self action:@selector(buttontapped:) forcontrolevents:uicontroleventtouchupinside]; mybutton.exclusivetouch = yes; mybutton.frame = cgrectmake(100, 100, 100, 100); [rv.view addsubview:mybutton]; homecoming yes; }
the issue somewhere else. code posted whole .h , .m myclass?
ios cocoa-touch uiview uibutton selector
Comments
Post a Comment