简体   繁体   English

快速使用两个视图控制器上的后退按钮

[英]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. 我曾尝试使用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 单独留下您的第二个视图控制器,而没有指向其他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 或者,您可以按照本教程使用unsegue segue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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