2
votes

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.

1
After the crash, open the Console (one of the options on the Run menu). It should tell you what the exception is.Frank Schmitt

1 Answers

2
votes

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. */
}