简体   繁体   English

NavigationBar BACK按钮不起作用

[英]NavigationBar BACK button not working

I have a NavigationViewController which root is a regular UIViewController. 我有一个NavigationViewController,其根是常规的UIViewController。 I present a TableViewController programatically by: 我通过以下方式以编程方式显示TableViewController:

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

This TableViewVC is showing the BACK button but it is not working at all. 该TableViewVC显示的是“返回”按钮,但它根本不起作用。

The segue to this TableViewVC is a "show/push" segue. 此TableViewVC的设置是“显示/推送”设置。

How to navigate back to the UIViewController? 如何导航回到UIViewController?

在此处输入图片说明

1. Add a UIBarbutton into navigation controller in showTableViewVC. 1.将一个UIBarbutton添加到showTableViewVC中的导航控制器中。

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. Implement back button Action. 2.实施后退按钮动作。

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

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

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