ios - When adding several subviews ( > 4), UIButton stops responding to touches -


i creating modal view in app, contains several subviews. each 1 of subviews has button , action related button. use loop insert each subview in place. problem first 4 subviews ok, 5th last there no responses.

here simplified code related problem:

simplified subviewview.m

- (id)initwithframe:(cgrect)frame {     self = [super initwithframe:frame];     if (self) {         // more info button         cgrect buttonframe = cgrectmake(infomarginleft + infowidthwithinfo, infoheightcontrol, 25, 25);         uibutton * button = [uibutton buttonwithtype:uibuttontypedetaildisclosure];         [button setframe:buttonframe];         [button addtarget:self action:@selector(buttontapped:) forcontrolevents:uicontroleventtouchupinside];         [self addsubview:button];     }     return self; }  -(void)buttontapped:(id)sender {     nslog(@"button tapped!"; } 

simplified view.m

- (void)drawrect:(cgrect)rect {      (int = 0; < 12; i++) {         // color info container         subviewview * miniview = [[subviewview alloc] initwithframe:cgrectmake(0, 20 * i, 15, 15)];         minicolorview.backgroundcolor = [uicolor clearcolor];          // adding subview through array keep track of objects         [self addsubview:minicolorview];     } } 

thanks in advance, have absolutely no ideia of what's going on :p

--

edit

just found out was!

the parent view had height screen height. thing is, of subviews beyond screen height limit. had increase parent view height =)

i check make sure not adding view miniview on top of button.

also should moved outside of drawrect, put in init method.

edit:

set miniview's background color besides clear, , see if still see button. if not, covered button, , won't receive touch events.


Comments