开发者

iPhone Error when myButton is pressed

开发者 https://www.devze.com 2022-12-16 03:08 出处:网络
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?

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:UIControlEv开发者_如何学JAVAentTouchUpInside];
[contentView addSubview:myButton];

any help would be great.


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

精彩评论

暂无评论...
验证码 换一张
取 消