使用自定义警报视图中的按钮在Swift

时间:2015-10-29 16:03:06

标签: ios swift segue uialertview

我正在开发一款简单的游戏。我创建了一个Pause按钮,用于打开自定义警报视图(我使用了vikmeup's SCLAlertView)。在此警报(view img)中,我希望其中一个按钮打开另一个名为MenuViewController的ViewController,其中包含Main Menu。那可能吗?如何为segue / unwind指定标识符?

这是我现在的代码:

@IBAction func menuButton(sender: AnyObject) {
    let alert = SCLAlertView()
    alert.addButton("button 1", target:self, selector:Selector("firstButton"))
    alert.showSuccess(kSuccessTitle, subTitle: kSubtitle) 
}

2 个答案:

答案 0 :(得分:1)

你的firstButton功能是什么?如果您在storyboard中创建MenuViewController,那么您可以实现这样的功能:

func firstButton() {
    let menuVC = self.storyboard!.instantiateViewControllerWithIdentifier("MenuViewControllerIdentifier")
    self.showViewController(menuVC, sender: self)
}

答案 1 :(得分:0)

试试这个,

1)为特定按钮添加按钮操作。

let alert = SCLAlertView()
alert.addButton("First Button", target:self, selector:Selector("firstButton")) // action for first button
alert.addButton("Second Button") {
print("Second button tapped")
}
alert.showSuccess(kSuccessTitle, subTitle: kSubtitle)


func firstButton() 
{
        //Do something
    let storyboard = UIStoryboard(name: "Main",bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("Identifier_name") 
    self.presentViewController(vc, animated: true, completion: nil)

}