【问题标题】:NavigationBar BACK button not working导航栏返回按钮不起作用
【发布时间】:2017-08-24 21:56:52
【问题描述】:

我有一个 NavigationViewController,它的根是一个常规的 UIViewController。 我通过以下方式以编程方式呈现 TableViewController:

self.performSegue(withIdentifier: "showTableViewVC", sender: nil)

这个 TableViewVC 正在显示 BACK 按钮,但它根本不起作用。

此 TableViewVC 的转场是“显示/推送”转场。

如何导航回 UIViewController?

【问题讨论】:

  • 您需要在之前的 VC 中添加另一个 segue 才能弹回,并添加执行该 segue 的操作
  • 如果我错了请纠正我,您没有使用UINavigationController 进行导航,您只使用segues 不是吗?
  • 我有一个嵌入根的 NavigationController。我使用 segue 来显示 DetailTableViewVC。
  • 那么你需要一个 segue 回到你以前的 viewController
  • 好的,但我无法“绘制”(单击选项)从后退按钮到 rootVC 的 segue。 (NavBar 是 XCode 自动添加的)

标签: ios swift uiviewcontroller uinavigationcontroller


【解决方案1】:

1.在 showTableViewVC 的导航控制器中添加 UIBarbutton。

override func viewDidLoad() {

     super.viewDidLoad()

     let backBarButton = UIBarButtonItem.init(barButtonSystemItem: .add, target: self, action: #selector(backButtonTapped(sender:))) as UIBarButtonItem 

     self.navigationItem.setLeftBarButton(backBarButton, animated: true)  

}

2。实现后退按钮操作。

func backButtonTapped(sender: UIBarButtonItem) 
{
    self.navigationController?.popViewController(animated: true)
}

【讨论】:

  • self.navigationController puts [<MyApp.ViewController: 0x101c0c0b0>, <MyApp.TableViewController: 0x101c56cc0>]. 所以它似乎正确堆叠了 backButtonTapped 被触发但 popViewController(animated: true)popToRoot 没有弹出。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-09-19
  • 2015-04-09
  • 1970-01-01
  • 1970-01-01
  • 2017-09-20
  • 1970-01-01
相关资源
最近更新 更多