我正在嘗試執行主螢屏快速操作以打開特定的視圖控制器,當我運行該應用程式Thread 1: EXC_BAD_ACCESS (code=261, address=0xdac11530)時,出現如下所示的錯誤。關于解決這個問題的任何想法?
func navigateToMoreDoggosVC() {
let storyBoard = UIStoryboard.init(name: "Main", bundle: nil)
let moreDoggosVC = storyBoard.instantiateViewController(withIdentifier: "moreDoggosViewController") //Thread 1: EXC_BAD_ACCESS (code=261, address=0x********)
let navVC = self.window?.rootViewController as? UINavigationController
navVC?.pushViewController(moreDoggosVC, animated: true)
}
如果您需要更多資訊,我很樂意編輯問題。
uj5u.com熱心網友回復:
您不能在啟動應用程式時推送視圖控制器。你需要設定 arootViewController然后讓它makeKeyAndVisible。
我們如何實作這一點,請參見下面的代碼:
func navigateToMoreDoggosVC() {
let storyBoard = UIStoryboard.init(name: "Main", bundle: nil)
let moreDoggosVC = storyBoard.instantiateViewController(withIdentifier: "moreDoggosViewController")
window?.rootViewController = UINavigationController(rootViewController: moreDoggosVC)
window?.makeKeyAndVisible()
}
您需要在SceneDelegate.swift檔案中添加此代碼并從willConnectTo函式中呼叫它。

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/361693.html
標籤:迅速 代码 exc-bad-access
