1
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    dismiss(animated: true) {
        let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ChatPage")
        self.present(viewController, animated: true, completion: nil)

        print("111")

    }
}

getting error while dismissing one view controller and moving to another viewcontroller by completionblock
please help me in solving this problem, I referred site but still I got stuck here.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Sri Vathsav
  • 91
  • 1
  • 1
  • 3
  • see this for example https://stackoverflow.com/questions/26022756/warning-attempt-to-present-on-whose-view-is-not-in-the-window-hierarchy-s – Anbu.Karthik Aug 06 '17 at 06:46

1 Answers1

1

It seems, that you are going to present "ChatPage" controller from current controller that is already dismissed. I think that this is the reason.

If your current controller is Modal, you can try something like this:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            dismiss(animated: true) {

        let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ChatPage")     

        //get access to presenting parent controller
        self.presentingViewController.present(viewController, animated: true, completion: nil)

        print("111")

    }
}

Or save parent controller instance in current controller, but this is not good code actually.

If this will not work, the other way is to use a delegate that will call some method in parent controller to present something. It means that you should call self.present(viewController, animated: true, completion: nil) from the controller that should present a new controller (in your case it is parent controller I guess), but not from controller that will be dismissed

Woof
  • 1,207
  • 1
  • 11
  • 21