Connect to ViewController from AppDelegate (Swift)

后端 未结 5 1169
Happy的楠姐
Happy的楠姐 2021-02-04 15:55

I have created a new OS X Cocoa Application using the standard Xcode Swift template (using StoryBoards).

I have implemented an IBAction in AppDelegate.swift to handle wh

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-04 16:23

    In Swift 5 and accessing new windows array:

    @IBAction func menuAction(sender: AnyObject) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let controller = storyboard.instantiateInitialViewController()
        // The windows in the array are ordered from back to front by window level;
        // thus, the last window in the array is on top of all other app windows.
        // On app launch, UIApplication.shared.windows.count == 1 anyway.
        if let window = UIApplication.shared.windows.last {
            window.rootViewController = controller
        }
    }
    

提交回复
热议问题