IPhone Error when theButton is pressed

iphone

I am getting an error message displayed below when my button is pressed. I do not yet have any code inside my "buttonPressed" method although I don't think that has anything to do with it?

Error Message: "terminate called after throwing an instance of 'NSException'
Program received signal: "SIGABRT".

UIButton * myButton = [UIButton buttonWithType:UIButtonTypeCustom];

[myButton setImage:[UIImage imageNamed:@"ButtonStandard.png"] forState:UIControlStateNormal];
[myButton setImage:[UIImage imageNamed:@"ButtonSelected.png"] forState:UIControlStateSelected];
[myButton setShowsTouchWhenHighlighted:YES];

myButton.frame = CGRectMake(0.0, 380.0, 320.0, 100.0);
[myButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:myButton];

any help would be great.

Best Answer

Change the @selector(buttonPressed) to @selector(buttonPressed:) (note the colon at the end) and change the method itself to:

-(void)buttonPressed:(id)sender {
    /* sender will be the UIButton. */
}
Related Topic