我需要学习如何基于if语句转到不同的viewcontroller。我对迅捷是全新的。我已经有了这个 - 当计数器达到5时,我需要它去一个不同的视图。
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)
}
}
答案 0 :(得分:2)
您可以通过segue或storyboard标识符的方式执行此操作。 使用以下代码:
// 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)
}
答案 1 :(得分:0)
使用
if // your statement { performSegueWithIdentifier(" segueOne&#34 ;, sender:nil)
}