Reputation: 115
I need to learn how to go to a different viewcontroller based on an if statement. I'm totally new to swift. I have this already - when the counter gets to 5, I need it to go to a different view.
class ViewController: UIViewController {
@IBOutlet var countNumber: UILabel!
var conta = 0
@IBAction func counterPlus(sender: AnyObject) {
conta++
if conta == 5{
//I WANT TO GO TO A DIFFERENT VIEWCONTROLLER HERE
}else
{
countNumber.text = String(conta)
}
}
Upvotes: 0
Views: 3745
Reputation: 115
Worked with
if // your statement { performSegueWithIdentifier("segueOne", sender: nil)
}
Upvotes: 0
Reputation: 2982
You could do this in a way of a segue, or with storyboard identifiers. Use the following code:
// segue method, also give your segue an identifier in storyboard
if // your statement {
performSegueWithIdentifier("yourIdentifier")
}
// storyboard identifier method, give your view controller an identifier in storyboard in the "identity inspector"
if // your statement {
let destinationController = storyboard.instantiateViewControllerWithIdentifier("yourIdentifier")
presentViewController(destinationController, animated: true, completion: nil)
}
Upvotes: 2