簡體   English   中英

navigationController.pushViewController 似乎在 Xcode 11 中不起作用?

[英]navigationController.pushViewController doesn't seem to work in Xcode 11?

我創建了一個基本的單視圖應用程序。 現在使用 Xcode 11。 我總是以編程方式構建應用程序,因為我開始使用的教程從不使用界面構建器。 由於某種原因無法讓 pushViewController 工作。 在我使用 Xcode 10 構建的其他項目中似乎工作得很好。

在應用程序委托中

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow()
        window?.makeKeyAndVisible()
        let nc = UINavigationController(rootViewController: ViewController())
        window?.rootViewController = nc

        return true
    }

在我的視圖控制器中

@objc func handleChat(){
    print("Chat pressed")
    navigationController?.pushViewController(InboxViewController(), animated: true)
}

AppDelegate.swift

var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        let VC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController") as? ViewController
        var Nav: UINavigationController? = nil
        if let VC = VC {
            Nav = UINavigationController(rootViewController: VC)
        }
        window?.rootViewController = Nav
        return true
    }

刪除 SceneDelegate.swift

轉到信息.plist

刪除應用場景清單

這對我有用。

暫無
暫無

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

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