您的位置:首页 > 移动开发 > Swift

swift页面跳转的集中方式归纳

2015-12-01 14:04 323 查看
1.选择属性栏的第三项

2.在Identifyt选项中填写 "storyboard ID"为post。这个ID根据自已的情况填写,后面的代码中会用到

3.重点来了,为登录按钮添加页面跳转代码

@IBAction func LoginButtonLicked(sender: AnyObject){

let myStoryBoard = self.storyboard

let anotherView:UIViewControl = myStoryBoard.instanceViewControllerWithIdentifier("post") as UIViewControl

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

}

//和上面同一种方式,实现方法不同,上次使用时上面一种方式好像不能用了,可以选择1,2来选用

//显示列表

//     let sb = UIStoryboard(name:"Main", bundle: nil)

//     let listController = sb.instantiateViewControllerWithIdentifier("demoList") as! DemoListViewController

//      self.presentViewController(listController, animated: true, completion: nil)

//////push方式

self.navigationController.pushViewController(vc, animated:true)    //返回是pop

//////present方式

self.presentViewController(vc, animated: true, completion: nil)    //返回改变vc为前一个

//////segue方式   拖线,然后重写方法prepareForSegue

    override func prepareForSegue(segue:

        UIStoryboardSegue, sender: AnyObject!) {

            if segue.identifier == "GoToGallery" {

                let index = beautyPicker.selectedRowInComponent(0)               

                var vc = segue.destinationViewController as! GalleryViewController

                    vc.imageName = "fanbingbing"   

            }

    }

/////返回方式 在前一个页面中重写一个方法,拖线到exit中后选择这个方法

@IBAction func close(segue: UIStoryboardSegue) {

        print("closed!")        

    }

///////////////////////////最后说一句,传值都是得到要跳转的页面,然后为这个页面的controller的属性赋值,然后在后一个页面就可以得到值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: