这就是我所拥有的。我已经创建了一个按钮并将其设置为一个动作,但是每次我单击该按钮都会使程序崩溃。为什么我的按钮不起作用?提前致谢。
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];
最佳答案
如果goToCurrentGamesViewController
的方法不带参数,请更改此行:
[currentGamesButton addTarget:self
action:@selector(goToCurrentGamesViewController:)
至:
[currentGamesButton addTarget:self
action:@selector(goToCurrentGamesViewController)
(从选择器中的方法中删除冒号
:
)关于ios - 以编程方式添加的按钮将无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10216113/