【问题标题】:Iboutlets have nil value on present callIboutlets 在当前通话中的价值为零
【发布时间】:2020-09-02 07:53:53
【问题描述】:
@objc func handleGoToSearch() {
//        present(UINavigationController(rootViewController: searchDisplayController()), animated: true, completion: nil)
        performSegue(withIdentifier: "searchSegue", sender: nil)
    }

我正在使用对 SearchViewController 的当前调用,但是 ib 插座在哪里为零,我感觉它与传递一个新实例有关,并且插座没有及时加载。 (我在其他地方读到的)。当我使用执行 segue 而不是错误时。

我想确切地知道发生了什么。我还认为可能 present() 不适用于情节提要,或者我传入了错误的值类型。

【问题讨论】:

  • present 确实适用于故事板。确保 ViewController 的类(在故事板中)正确设置为 swift 类

标签: ios swift uistoryboardsegue iboutlet


【解决方案1】:

您的 outlet 是 nil,因为您不是仅从 Swift 类创建视图控制器,而不是从情节提要。要从情节提要创建视图控制器,请执行以下操作:

let viewController = UIStoryboard(name: "Name of the storyboard").instantiateViewController(withIdentifier: "Identifier of the viewcontroller")

您应该填写情节提要的名称(通常为Main)并在情节提要中给视图控制器一个标识符,并在代码中使用该标识符。

【讨论】:

    猜你喜欢
    • 2014-11-14
    • 2016-10-30
    • 2011-04-29
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多