美文网首页Swift学习
Swift-ViewController之间的跳转,传值

Swift-ViewController之间的跳转,传值

作者: Themores | 来源:发表于2015-08-06 00:17 被阅读7119次

    接触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 来传值。

    相关文章

      网友评论

        本文标题:Swift-ViewController之间的跳转,传值

        本文链接:https://www.haomeiwen.com/subject/fqxbqttx.html