I would like to add UIButton using for loop. Each button would have a different action.
My code is:
NSArray *methods = [[NSArray alloc]initWithObjects:@"1",@"2", @"3", @"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15", nil];
int x=0;
for (int t=0;t<=14;t++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector([methods[t]]) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"" forState:UIControlStateNormal];
button.frame = CGRectMake(275, x+8, 28, 16);
[button setBackgroundColor:[UIColor colorWithRed: 10.0/255.0f green:100.0/255.0f blue:150.0/255.0f alpha:1.0f]];
button.layer.cornerRadius = 10;
[button setBackgroundImage:[UIImage imageNamed:@"Plus"] forState:UIControlStateNormal];
[segmentedView1 addSubview:button];
[self.view addSubview:segmentedView1];
x+=20;
}
Stuck with an error:
"Expected identifier" in the line [button addTarget:self action:@selector([methods[t]])
Also,how do i make outlets for such buttons added programatically?
Any solution? Thank you