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

后端 未结 16 616
盖世英雄少女心
盖世英雄少女心 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:34

    For me it was an alert that was interfering with the new VC that I was about to present.

    So I moved the new VC present code into the OK part of my alert, Like this :

        func showSuccessfullSignupAndGoToMainView(){
    
        let alert = UIAlertController(title: "Alert", message: "Sign up was successfull.", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
            switch action.style{
            case .default:
                // Goto Main Page to show businesses
                let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
                let vc : MainViewController = mainStoryboard.instantiateViewController(withIdentifier: "MainViewController") as! MainViewController
                self.present(vc, animated: false, completion: nil)
    
            case .cancel:
                print("cancel")
    
            case .destructive:
                print("destructive")
    
            }}))
        self.present(alert, animated: true, completion: nil)
    }
    
    0 讨论(0)
  • 2021-02-03 17:36

    This is what finally worked for me, as my project didn't exactly have a NavigationVC but instead, individual detached VC's. as xib files

    This code produced the bug:

    present(alertVC, animated: true, completion: nil)
    

    This code fixed the bug:

     if presentedViewController == nil{
            navigationController?.present(alertVC, animated: true, completion: nil)
        }
    
    0 讨论(0)
  • 2021-02-03 17:36

    More than likely you have your Search button wired directly to the other view controller with a segue and you are calling performSegueWithIdentifier. So you are opening it twice, which generates the error that tells you "is already presenting."

    So don't call performSegueWithIdentifier, and that should do the trick.

    0 讨论(0)
  • 2021-02-03 17:38

    My issue was that I was trying to present an alert from a view that wasn't on top. Make sure you present from the top-most viewController.

    0 讨论(0)
  • 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 <MY_HOME_VIEW_CONTROLLER> 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)
    }
    
    0 讨论(0)
  • 2021-02-03 17:43

    What worked for me was to add the presentation of the alert to the main thread.

    DispatchQueue.main.async {
       self.present(alert, animated: true)
    }
    

    The presentation of the current viewController was not complete. By adding the alert to the main thread it can wait for the viewController's presentation to complete before attempting to present.

    0 讨论(0)
提交回复
热议问题