以编程方式添加按钮不起作用

时间:2012-04-18 18:59:46

标签: ios uibutton programmatically-created

所以这就是我所拥有的。我创建了一个按钮并将其设置为动作,但每次单击该按钮都会导致程序崩溃。为什么我的按钮不起作用?提前谢谢。

UIButton *currentGamesButton = [UIButton buttonWithType:UIButtonTypeCustom];
currentGamesButton.frame = CGRectMake(124,18,72,65);
[currentGamesButton addTarget:self
                       action:@selector(goToCurrentGamesViewController:)
             forControlEvents:UIControlEventTouchDown];
UIImage *currentGamesPNG = [UIImage imageNamed:@"CurrentGamesHighlightedState.png"];
[currentGamesButton setBackgroundImage:currentGamesPNG forState:UIControlStateNormal];
[self.view addSubview:currentGamesButton];

1 个答案:

答案 0 :(得分:4)

如果goToCurrentGamesViewController的方法不带参数,请更改此行:

[currentGamesButton addTarget:self
                   action:@selector(goToCurrentGamesViewController:)

为:

[currentGamesButton addTarget:self
                   action:@selector(goToCurrentGamesViewController)

(从选择器中的方法中删除冒号:

相关问题