【发布时间】:2016-02-25 08:21:18
【问题描述】:
当我再次按下播放按钮时,它不起作用。我只有这段代码涉及再次播放按钮。我应该在这里添加什么?如何向playAgain 按钮添加功能?这是我的代码:
let playAgain: UIButton = UIButton(frame: CGRectMake(-10, 400, 400, 150))
playAgain.setTitle("Play Again", forState: UIControlState.Normal)
playAgain.titleLabel!.font = UIFont(name: "Helvetica", size: 50)
playAgain.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
playAgain.tag = 1
self.view!.addSubview(playAgain)
【问题讨论】:
-
你的
buttonAction实现是什么样的? -
我没有buttonAction。我不知道我该如何使用它。
-
你需要实现你的buttonAction:
func buttonAction(sender:UIButton!) { //Your code here when you press the playAgain button println("Button tapped") }这个方法会在你按下playAgain按钮的时候被调用,在你的视图控制器中实现它就行了
标签: xcode swift uibutton sprite-kit