按下按钮时出现iPhone错误

时间:2010-01-07 00:50:49

标签: iphone

按下按钮时,我收到一条错误信息。我的“buttonPressed”方法中还没有任何代码,尽管我认为它与它没有任何关系?

错误消息:“抛出'NSException'实例后调用终止 程序收到信号:“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];

任何帮助都会很棒。

1 个答案:

答案 0 :(得分:2)

@selector(buttonPressed)更改为@selector(buttonPressed:)(注意末尾的冒号)并将方法本身更改为:

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