快速呈现新VC时应用程序卡住

我正在尝试提供一个新的VC,但是当我点击代码应用程序时,它被卡住了,无法执行任何操作。这是一个很奇怪的问题,我该如何解决?我展示新VC的代码是这样,

let vc : PropertyDetailController! =
        uistoryboard.viewController(identifier: "PropertyDetailController",storyBoard: "Explore") as? PropertyDetailController

    vc.propertyDetailData = property
    vc.hidesBottomBarWhenPushed = true
    vc.modalTransitionStyle = .crossDissolve
    vc.modalPresentationStyle = .fullScreen
    self.navigationController?.present(vc,animated: true,completion: nil)

这就是它在控制台中显示的内容,

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

它不存在新的VC。这就是我的应用卡住的方式,请检查gif链接, enter link description here

S329817566 回答:快速呈现新VC时应用程序卡住

正如我在您的代码中看到的那样,您正在使用新的故事板,因此有必要通过UINavigationController

其中一个示例代码可能会对您有所帮助

let storyBoard: UIStoryboard = UIStoryboard(name: "YOUR_STORYBOARD",bundle: nil)
let aVC: YOUR_VC = storyBoard.instantiateViewController(withIdentifier: "YOUR_VC_ID") as! YOUR_VC
let navigationController = UINavigationController(rootViewController: aVC)
self.present(navigationController,animated: true,completion: nil)
,

[在此处输入图片描述] [1]首先确保当前视图控制器已嵌入导航控制器。

现在使用以下代码解决此问题。

let storyboard = UIStoryboard(name: "Explore",bundle: nil)

        guard let vc = storyboard.instantiateViewController(withIdentifier: "PropertyDetailController") as? PropertyDetailController else {return}
        vc.hidesBottomBarWhenPushed = true
        vc.modalTransitionStyle = .crossDissolve
        vc.modalPresentationStyle = .fullScreen
        self.navigationController?.present(vc,completion: nil)


  [1]: https://i.stack.imgur.com/c7iBr.png
,

如果要显示视图控制器,请尝试
self.present(vc,completion: nil)

如果要推送视图控制器,请尝试
self.navigationController?.pushViewController(vc,animated: true)

,

尝试将推送代码移至主线程

DispatchQueue.main.async {[weak self] in
    self?.navigationController?.pushViewController(vc,animated: true)
}

存在或推送,所有UI处理都必须在主线程上完成。

编辑:

如果要显示vc,请使用

DispatchQueue.main.async {[weak self] in
    self?.present(vc,completion: nil)
}
本文链接:https://www.f2er.com/3154738.html

大家都在问