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

标签 swift uinavigationcontroller storyboard segue viewdidload

我有三个 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/

相关文章:

xcode - 在 NSScrollView 中显示文本 (Swift)

image - 在 uicollectionview 上快速将图像传递给详细 View Controller

ios - 静态单元格 - socket 始终为零

ios - 防止 leftBarButtonItem 导航项显示警报

ios - UIViewControllers IOS 之间的导航

iOS Storyboards 我应该使用它们吗?

swift - 根据父 UITableVIew 的节索引设置嵌套 UITableView 的行数

iphone - 如何在通过 Storyboard添加的 UINavigationController 中设置 UINavigationItem 的颜色?

iphone - 如何更改 Storyboard上 View Controller 的大小以进行编辑?

ios - UITableView 在嵌入容器内部的 Controller 之间传递数据