How to prevent present modally an active controller?

前端 未结 4 1121
情歌与酒
情歌与酒 2021-01-11 16:11

We have 2 controllers: MainVC and ProfileVC. From MainVC we go to ProfileVC with profileButton press (left item on navigation bar).

In Profile VC we hav

4条回答
  •  猫巷女王i
    2021-01-11 16:48

    There may be another case for other developers:

    Is the target ViewController presented after a connection triggered by a button? The user may be clicking twice, making two connections and opening the same ViewController twice, if you have a shared instance of the said ViewController.

    Prevent it by doing something like this:

    var didSuccess = false
    
    func success(result: LoginModel.Result) {
        if didSuccess {
            return
        }
        didSuccess = true
        present(MainTabBarController.sharedInstance, animated: true, completion: nil)
    }
    

    Or disabling the button during connection.

提交回复
热议问题