How to Remove a Previous ViewController

前端 未结 5 1841
予麋鹿
予麋鹿 2021-02-02 16:48

I am a student and pretty new to programming. I am trying to learn Objective-C/Swift in my spare time. I made a game using spriteKit with swift that has multiple menus/scenes. <

5条回答
  •  暖寄归人
    2021-02-02 17:41

    I guess best implementation is to place the following at the previous View Controller - Swift

        // Override to remove this view from the navigation stack
        override func viewDidDisappear(animated: Bool) {
            super.viewDidDisappear(animated)
            // Remove self from navigation hierarchy
            guard let viewControllers = navigationController?.viewControllers,
                let index = viewControllers.indexOf(self) else { return }
            navigationController?.viewControllers.removeAtIndex(index)
        }
    

提交回复
热议问题