Warning: Attempt to present * on * which is already presenting (null)

后端 未结 16 611
盖世英雄少女心
盖世英雄少女心 2021-02-03 17:14

This is my first application for iOS.

So I have a UIVIewController with a UITableView where I have integrated a UISearchBar and a

16条回答
  •  执笔经年
    2021-02-03 17:43

    This happened with me on our project. I was presenting our log in/log out ViewController as a pop-over. But whenever I tried to log back out again and display the pop-over again, I was getting this logged out in my console:

    Warning: Attempt to present UIViewController on which is already presenting (null)

    My guess is that the pop-over was still being held by my ViewController even though it was not visible.

    However you are attempting to display the new ViewController, the following code I used to solve the issue should work for you:

    func showLoginForm() {
    
        // Dismiss the Old
        if let presented = self.presentedViewController {
            presented.removeFromParentViewController()
        }
    
        // Present the New
        let storyboard = UIStoryboard(name: "MPTLogin", bundle: Bundle(for: MPTLogin.self))
        let loginVC = storyboard.instantiateViewController(withIdentifier: "LogInViewController") as? MPTLogInViewController
        let loginNav = MPTLoginNav(rootViewController: loginVC!)
        loginNav.modalPresentationStyle = .pageSheet;
        self.present(loginNav, animated: true, completion: nil)
    }
    

提交回复
热议问题