簡體   English   中英

無法實例化View Controller

[英]Unable to Instantiate View Controller

我有一個函數,通過它可以檢查是否設置了UserDefaults,如果沒有,則打開一個新的View Controller並顯示一個登錄屏幕,該屏幕將設置用戶默認值。

我的問題是視圖控制器沒有實例化,但是我得到打印“用戶未注冊”

func checkUserAccount() {
        let defaults = UserDefaults.standard
        let accountName = defaults.bool(forKey: "PUserAccountName")
        let accountPassword = defaults.bool(forKey: "PUserAccountPassword")
        if accountName == true && accountPassword == true  {
            print("User Registered")

        } else {

            let storyboard: UIStoryboard = UIStoryboard(name: "PolTRiM", bundle: nil)
            let vc: StudentLoginVC  = storyboard.instantiateViewController(withIdentifier: "studentLogin") as! StudentLoginVC
            vc.modalPresentationStyle = .custom
            vc.modalTransitionStyle = .crossDissolve
            self.present(vc, animated: true, completion: { _ in })
            print("User not registered")
        }

    }

有什么想法嗎?

您是否仔細檢查過UIStoryBoard名稱和UIViewController標識符(如果編寫正確)? 否則這段代碼對我有用

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier :"MyViewController") as! UIViewController
self.present(viewController, animated: true)    

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM