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

时间:2019-11-06 05:46:04

标签: ios swift

我正在尝试提供一个新的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

4 个答案:

答案 0 :(得分:1)

正如我在您的代码中看到的那样,您正在使用新的故事板,因此有必要通过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 :(得分:0)

[在此处输入图片描述] [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, animated: true, completion: nil)


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

答案 2 :(得分:0)

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

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

答案 3 :(得分:0)

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

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

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

编辑:

如果要显示vc,请使用

DispatchQueue.main.async {[weak self] in
    self?.present(vc, animated: true, completion: nil)
}