简体   繁体   English

UINavigationItem上的touchUpInside事件

[英]touchUpInside event on a UINavigationItem

In my app's main view, I have a button that segues to a subclassed UINavigationController holding a UITableViewController to change settings. 在我的应用程序的主视图中,我有一个按钮可以连接到一个子类UINavigationController ,该子类持有一个UITableViewController来更改设置。

To get back to the app's main view, I have this in the UINavigationController subclass: 回到应用程序的主视图,我在UINavigationController子类中具有此功能:

navigationBar.setItems([UINavigationItem(title: "Back"), 
                        UINavigationItem(title: "Settings")], 
                        animated: false)

When I tab the Back button, the app segues back to the same view - but the navigation bar now only have the Settings item. 当我点击“后退”按钮时,该应用会重新显示为同一视图-但导航栏现在仅具有“设置”项。

When I click the Back button, I want to dismiss the UINavigationController subclass and come back to my main view. 当我单击“后退”按钮时,我想关闭UINavigationController子类并返回到主视图。

So how do I get a touchUpInside event on the UINavigationItem or is there some other way I can do this? 那么如何在UINavigationItem上获取touchUpInside事件,或者还有其他方法可以做到这一点?

So it turns out there's a very easy way of doing this: 事实证明,有一种非常简单的方法:

  • adding a UIBarButtonItem in the storyboard 在情节UIBarButtonItem中添加UIBarButtonItem
  • subclass the UITableViewController 子类化UITableViewController
  • control-drag from the UIBarButtonItem to the UITableViewController subclass to create an action 控制从UIBarButtonItem拖动到UITableViewController子类以创建操作
  • dismiss the UITableViewController in the action 在动作中关闭UITableViewController

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

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