I have created a several buttons like this:
[self makeButtonsWithX:0.0f y:180.0f width:640.0f height:80.0f color:[UIColor colorWithRed:0.796 green:0.282 blue:0.196 alpha:1] button:self.redButton];
[self makeButtonsWithX:0.0f y:260.0f width:640.0f height:80.0f color:[UIColor colorWithRed:0.761 green:0.631 blue:0.184 alpha:1] button:self.yellowButton];
using this function:
- (void)makeButtonsWithX:(CGFloat)x y:(CGFloat)y width:(CGFloat)width height:(CGFloat)height color:(UIColor *)color button:(UIButton *)button
{
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(x, y, width, height);
button.backgroundColor = color;
[self.view addSubview:button];
[button addTarget:self action:@selector(tappedButton:) forControlEvents:UIControlEventTouchUpInside];
}
When I tap one of them I want to know which one was tapped, using this function:
- (void)tappedButton:(UIButton *)button
{
//NSLog(@"tapped");
if ([button isEqual:self.redButton]) {
NSLog(@"Red");
}
}
Nothing happens. If I uncomment the first NSLog in the last function however, it prints every time I press a button (doesn't matter which one). Why isn't my if-statement working?
Cheers.