How to correctly dismiss a UINavigationController that's presented as a modal?

后端 未结 8 1804
情话喂你
情话喂你 2021-02-01 16:04

In my TabBarViewController, I create a UINavigationController and present it as a modal.

var navController =  UINavigationController()
let messageVC         


        
8条回答
  •  难免孤独
    2021-02-01 16:37

    No need to have member for navController. Use following code to present your MessagesViewController.

    let messageVC = self.storyboard?.instantiateViewControllerWithIdentifier("MessagesViewController") as! MessagesViewController
    let pesentingNavigationController = UINavigationController(rootViewController: messageVC)
    self.presentViewController(pesentingNavigationController, animated: true, completion: nil)
    

    Your dismiss view controller code will be

    func swipedRightAndUserWantsToDismiss() {
      self.navigationController.dismiss(animated: true, completion: nil)
    }
    

提交回复
热议问题