iphone - UIButton with custom view - addTarget:action:forControlEvents: does not work -
my button follows
- created label1
- created label2
- created customview (
uiview
) - added label1 , label2 on custom view
- created mycustombutton(
uibutton
) - added customview on mycustombutton
i have done userinteractionenable custom_view, label1 , label2.
then added
[mycustombutton addtarget:self action:@selector(onbuttonclick:) forcontrolevents:uicontroleventtouchupinside];
and
-(void)onbuttonclick:(uibutton *)sender { }
but above function never called when touch button. solution?
just minor problem code friend, need add 1 following line code, forget setuserinteractionenabled:no
uiview
allow click button
uilabel *lbl1 = [[uilabel alloc] initwithframe:cgrectmake(0, 0, 100, 30)]; [lbl1 settext:@"one"]; uilabel *lbl2 = [[uilabel alloc] initwithframe:cgrectmake(0, 30, 100, 30)]; [lbl2 settext:@"two"]; uiview * view = [[uiview alloc] initwithframe:cgrectmake(0, 0, 200, 130)]; [view setuserinteractionenabled:no]; [view addsubview:lbl1]; [view addsubview:lbl2]; uibutton *btn = [uibutton buttonwithtype:uibuttontypecustom]; [btn addsubview:view]; [btn setframe:cgrectmake(0, 0, 200, 130)]; [btn addtarget:self action:@selector(click) forcontrolevents:uicontroleventtouchupinside]; [self.view addsubview:btn];
click method
-(void)click { nslog(@"%s",__function__); }
Comments
Post a Comment