Mar*_*tin 7 storyboard uinavigationcontroller viewdidload segue swift
我有三个视图(视图1检查服务器连接,视图2显示主要内容,view3显示支持页面),我在故事板中创建它们而不编码.在启动我的iOS应用程序时,视图1在检查服务器连接时显示一个微调器.如果连接检查通过,那么我想去查看2,如果它失败了,那么我想去查看3.视图1仅用于连接检查,我不想回到这个视图.所以,我想我不需要导航控制器,或者?
在故事板中,我将所有视图与seques连接起来.在我的视图控制器1中我这样做:
override func viewDidLoad() {
super.viewDidLoad()
let result:Bool = server.isServerAvailable(myURL)
if (result == true) {
performSegueWithIdentifier("ConnectionCheckToMain", sender: self)
}
else {
performSegueWithIdentifier("ConnectionCheckToSupport", sender: self)
}
}
Run Code Online (Sandbox Code Playgroud)
但是这个viewDidLoad()函数中的segue 不起作用,但我不知道为什么.我在视图上添加了一个按钮来检查它.我已经实现了相同的代码viewDidLoad(),它工作正常.单击按钮时,将加载下一个视图.
有什么想法代码不起作用吗?
小智 5
此代码使用"segue"解决了我(Swift 3)(请将"ConnectionCheckToMain"替换为您的segue名称.
DispatchQueue.main.async(execute: {
self.performSegue(withIdentifier: "ConnectionCheckToMain", sender: nil)
})
Run Code Online (Sandbox Code Playgroud)
您可以使用此代码进行导航。
let vc : UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ConnectionCheckToMain") as! UIViewController;
self.presentViewController(vc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)