Hi Folks,
I am creating a couple of Buttons dynamically like this:
Code:
t = 0;
x = 10;
y = 10;
for (i=0; i < [count intValue]; i++ ){
UIImage *imageLoop = [UIImage imageNamed:[[companyName objectAtIndex:i ]stringByAppendingString:@".png"]];
NSLog(@"NSMutableArray: %@", [companyName objectAtIndex:i]);
UIButton* button = [[UIButton alloc] init];
[button setImage:imageLoop forState:UIControlStateNormal];
[button setImage:imageLoop forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(productImagePressed:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = t;
button.frame = CGRectMake(x,y,100,100);
[self.view addSubview:button];
[button release];
x = x + 120;
y = y;
t = t + 1;
}
In my "productImagePressed" Method I am logging like this:
Code:
-(IBAction)productImagePressed:(id)sender {
NSLog(@"Pressed = %@", [companyName objectAtIndex:t]);
}
But I am not able to get the correct number - I know that my "t" is wrong, but how can I fetch the pressed button?
Thanks for your Feedback and Advice.