gpt4 book ai didi

swift - 在 Swift 中没有导航 Controller 的情况下在 viewDidLoad() 中执行 segue

转载 作者:搜寻专家 更新时间:2023-10-30 21:54:11 25 4
gpt4 key购买 nike

我有三个 View ( View 1 检查服务器连接, View 2 显示主要内容, View 3 显示支持页面)并且我在 Storyboard 中创建了它们而没有编码。在启动我的 iOS 应用程序时, View 1 在检查服务器连接时显示一个微调器。如果连接检查通过,那么我想去 View 2,如果它失败了,那么我想去 View 3。 View 1 仅用于连接检查,我不想回到这个 View 。所以,我认为我不需要导航 Controller ,还是?

在 Storyboard中,我将所有 View 与序列连接起来。在我的 View 1 的 View Controller 中,我这样做:

override func viewDidLoad() {
super.viewDidLoad()

let result:Bool = server.isServerAvailable(myURL)

if (result == true) {
performSegueWithIdentifier("ConnectionCheckToMain", sender: self)
}
else {
performSegueWithIdentifier("ConnectionCheckToSupport", sender: self)
}
}

但是viewDidLoad()函数中的这个segue不起作用,但我不知道为什么。我在 View 上添加了一个按钮来检查它。我已经实现了与 viewDidLoad() 中相同的代码,并且运行良好。单击该按钮,将加载下一个 View 。

知道为什么代码不起作用吗?

最佳答案

此代码使用“segue”为我 (Swift 3) 解决了问题(请将“ConnectionCheckToMain”替换为您的 segue 名称。

DispatchQueue.main.async(execute: {
self.performSegue(withIdentifier: "ConnectionCheckToMain", sender: nil)
})

关于swift - 在 Swift 中没有导航 Controller 的情况下在 viewDidLoad() 中执行 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26100220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com