iphone - Unable to programmatically set UIButton action -


i'm having bit of trouble action on uibuttons. i'm creating 4 buttons programmatically i'm not able touchupinside event fire.

i've had read through i'm still having trouble pointers appreciated!

here's code create , set button , it's action:

uibutton *btn;  float newwidth = 10;  (int = 0; < _btnimages.count; ++i) {     btn = [uibutton buttonwithtype:uibuttontyperoundedrect];     cgrect imageframe = cgrectmake(/*x*/newwidth, /*y*/height - 80, 65, 65);     btn.frame = imageframe;     btn.tag = i;      [btn setbackgroundimage:[uiimage imagenamed:[_btnimages objectatindex:i]] forstate:uicontrolstatenormal];     [btn addtarget:self             action:@selector(btnselected:)             forcontrolevents:uicontroleventtouchupinside];     [btn setenabled:true];      [self addsubview:btn];     newwidth = newwidth + 75; } 

and here btnselected method:

-(void)btnselected:(uibutton *)button {     nslog(@"button %ld clicked",(long int)[button tag]); }  

the code have shown okay. possible problems are:

  1. you adding buttons view has user interaction disabled (or of ancestor has user interaction disabled).

  2. your buttons clipped superview. make sure buttons inside bounds of superview (and superview inside bounds of superview etc.).

  3. other issues can happen when there gesture recognizers on views - can delay & cancel touches in subviews, including buttons. make sure touch event not handled gesture recognizer.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -