Note that there are some explanatory texts on larger screens.

plurals
  1. POUIButton handling in array
    text
    copied!<p>I created array of buttons, but i am not see, that buttons handles touch events ( buttonEvent: not calls)</p> <p>This my code - is it not correct ?</p> <pre><code>- (void)loadView{ CGRect screenRect = [[UIScreen mainScreen] applicationFrame]; UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:screenRect]; [backgroundImageView setImage:[UIImage imageNamed:@"background.png"]]; backgroundImageView.opaque = YES; self.view = backgroundImageView; [backgroundImageView release]; CGRect brandRect = CGRectMake(90, 25, 140, 70); UIImageView *brandImageView = [[UIImageView alloc] initWithFrame:brandRect]; [brandImageView setImage:[UIImage imageNamed:@"brand.png"]]; [self.view addSubview:brandImageView]; buttons = [NSMutableArray array]; int y = 100; for ( int i = 0 ; i &lt; 5; i++ ){ UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setFrame:CGRectMake(20, y, 280, 50)]; if ( i == 0 ){ [button setBackgroundImage:[UIImage imageNamed:@"select_active.png"] forState:UIControlStateNormal]; } else { [button setBackgroundImage:[UIImage imageNamed:@"select_passive.png"] forState:UIControlStateNormal]; } [button setTitle:[NSString stringWithFormat:@"Object%d",i] forState:UIControlStateNormal]; [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventAllEvents]; button.tag = 1000 + i ; [self.view addSubview:button]; y += 60; } -(void)buttonEvent:(id)sender { NSLog(@"new button clicked!!!"); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload