2016-07-22 44 views
-2

喜我想去与条件下一个视图中textfiled 2进入secondview和tetxtfiled 3去时thirdview变化与条件

我不想navgation控制或标签视图

class ViewController: UIViewController { 

@IBOutlet weak var text: UITextField! 
@IBAction func nextview(sender: UIButton) { 

    if text.text == "2"{ 

     let secondView = self.storyboard?.instantiateViewControllerWithIdentifier("second") as! SecondView 
     self.navigationController?.pushViewController(secondView, animated: true) 
    } 
    else{ 

     let thirdPageView = self.storyboard?.instantiateViewControllerWithIdentifier("third") as! ThirdView 
     self.navigationController?.pushViewController(thirdPageView, animated: true) 
    } 

} 
override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 
} 

我也使用prepersguewithidentifire,但不工作! 我很困惑

+0

其中是self.storyboard的初始化? –

+0

嗨。在mainstoryboard - >故事板识别 –

+0

你是什么意思的“不工作”? – Sweeper

回答

0

如果你想要你prepareForSegue(segue:UIStoryboardSegue,sender:AnyObject?)方法被调用,你需要执行segue。在您的代码中,您只是将视图控制器推送到导航堆栈而不执行segue。

如果在你的故事板一个赛格瑞你可以叫self.navigationController .pushViewController的

func performSegueWithIdentifier(_ identifier: String, 
         sender sender: AnyObject?) 

isntead(thirdPageView,动画:真)?你只需要创建第二和第三两种不同的塞格斯view controller