Swift开发教程--使用Storyboard进行界面跳转

使用storyboard结合代码来做确实能够给开发带来非常多的便利。

在实践的过程中,我们常常会遇到界面的跳转问题。

通过控件和界面的建立的“连接”就能够了。

假设是navigationcontroller的跳转,则选择push的方式(否则xcode执行的时候会报错);

假设是Viewcontroller的跳转,则选择modal的方式。

假设你想通过代码来打开另外一个界面。则须要设置他们之间连接的segue.identifier,比方你设置为jumpid。

然后代码就能够这么写:

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


假设你还想在跳转的时候传递数值过去。你能够这么写:

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

        if(segue.identifier == "jumpid") {

            var barInfo:BarInfoViewController = segue.destinationViewController as! BarInfoViewController;

            barInfo.name = "david";

            barInfo.age = 99;

        }

    }


posted @ 2017-07-20 12:35  zsychanpin  阅读(638)  评论(0编辑  收藏  举报