简体   繁体   中英

Swift Using a Back Button on Two View Controllers

My second view controller is a table view controller. I wish to segue to a first view controller with a back button. I have tried using Editor>Embed In>Navigation Controller. It places a navigation bar on the top where I can place an Item (Back button) on it, and after segueing it back to my first view controller, it becomes very screwy (it shows two navigation bars on top of each other). Is there a better/easier way to move back to my first view controller?

if u want to use navigation controller to manage ur push&pop stuff, just make sure:

  1. navigation controller is ur initial view controller
  2. ur first view controller is the root view controller of navigation controller
  3. set an unique identifier to second view controller
  4. leave ur second view controller alone without any link to other vc

like this

then push like this

let secondVC = (self.storyboard?.instantiateViewControllerWithIdentifier("identifier"))! as! urVC secondVC.title = "second view controller" self.navigationController?.pushViewController(secondVC, animated: true)

and pop like this

 self.navigationController?.popViewControllerAnimated(true)

alternatively, u can use unwind segue following this tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM