Corrado
Corrado

Reputation: 41

Use a button in a Custom Alert View to segue in another ViewController in Swift

I am developing a simple game. I created a Pause button that open a custom Alert View (I used the vikmeup's SCLAlertView). In this alert (view img) I want that one of this button opens another ViewController called MenuViewController that include Main Menu. Is that possible? And how can I assign an identifier for the segue/unwind?

This is my code right now:

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

Upvotes: 0

Views: 783

Answers (2)

Manikandan D
Manikandan D

Reputation: 1442

Try this,

1) Add button action for particular button.

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)

}

Upvotes: 0

kientux
kientux

Reputation: 1792

What is your firstButton function? If you create MenuViewController in storyboard, then you can implement the function like this:

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

Upvotes: 1

Related Questions