Swift学习

Swift-ViewController之间的跳转,传值

2015-08-06  本文已影响7119人  Themores

接触swift 刚刚不久,由于从android 开发转到iOS,于是第一件事就是如何进行页面之间进行跳转和传值

跳转方式:

1.storyboard中的segue 跳转方式:

self.performSegueWithIdentifier("next",sender:self);

"next"为 ,segue中在sb中设置的Identifier 的id

传值方式:

// In a storyboard-based application, you will often want to do a little preparation before navigation

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

// Get the new view controller using segue.destinationViewController.

// Pass the selected object to the new view controller.

let dev=segue.destinationViewController as! NextViewController

//segue 在sb 中的传值

dev.nexttext="pass"

}

2.普通的xib 界面的view controller 跳转方式以及传值方式

var nib=XibViewController()//需要跳转的viewcontroller

self.presentViewController(nib, animated:true, completion: nil)

//传值

nib.xibtest.text="连接超时"

3.关闭当前的viewcontroller

self.dismissViewControllerAnimated(true, completion: nil)

4.也可以用protocol 来传值。

上一篇下一篇

猜你喜欢

热点阅读