简体   繁体   English

UITabBarController的子视图控制器中的导航栏按钮无响应

[英]Navigation bar button unresponsive in child view controller of UITabBarController

I instantiate my UITabBarController by calling navigationController.viewControllers = @[[self.storyboard instantiateViewControllerWithIdentifier:@"tabController"]]; 我通过调用navigationController.viewControllers = @[[self.storyboard instantiateViewControllerWithIdentifier:@"tabController"]];实例化我的UITabBarController navigationController.viewControllers = @[[self.storyboard instantiateViewControllerWithIdentifier:@"tabController"]];

My Tab bar controller has a child view that is embedded in a navigation controller. 我的标签栏控制器具有嵌入在导航控制器中的子视图。 However the bar button ( item ) is unresponsive when I touch them (the buttons in the navigation bar). 但是,当我触摸条形按钮( item )时(导航栏中的按钮),它们没有响应。 I have tried logging the action but it appears as if the button is not firing at all. 我已尝试记录该操作,但它似乎根本没有触发该按钮。

The only thing that I have done differently is the way i instantiated the tab bar controller. 我唯一做的不同的事情是我实例化标签栏控制器的方式。 Am I missing something? 我想念什么吗?

I connected the navigation bar button from the storyboard to an action so it is hooked up successfully. 我将情节提要中的导航栏按钮连接到一个动作,因此它已成功连接。 Please note there is also a navigation Controller pointing to the UITabbarController not shown below. 请注意,还有一个导航控制器指向未在下面显示的UITabbarController。

在此处输入图片说明

在此处输入图片说明

The unwanted behaviour maybe because this flow (navigation controller to tabbar controller) is ill advised in the Apple HIG. 不良行为可能是因为在Apple HIG中不建议使用此流程(导航控制器到选项卡控制器)。 More information can be found here: Storyboard with NavigationController and TabController . 在此处可以找到更多信息: 带有NavigationController和TabController的情节提要 The solution I found was to hide the navigation bar on the navigation controller that links to the navigation bar (can be done in interface builder), then make it reappear in the new navigation controller that the tab bar links to. 我发现的解决方案是隐藏链接到导航栏的导航控制器上的导航栏(可以在界面生成器中完成),然后使其重新出现在选项卡栏链接到的新导航控制器中。 Confusing I know, I can help anyone who ever has a similar issue. 我知道,我可以为任何遇到类似问题的人提供帮助。

Is there any specific reason you are doing this: 您这样做是否有任何特定原因:

navigationController.viewControllers = @[[self.storyboard instantiateViewControllerWithIdentifier:@"tabController"]];

You can simply drag an outlet from the UITableViewController to the UINavigationController using only the Storyboard. 您可以仅使用Storyboard将插座从UITableViewController拖到UINavigationController。

I think you forgot to add the navigationItem. 我认为您忘记添加navigationItem。 In the storyboard, add a navigation Item to your viewController and move your bar button items to the navigation bar that appears on the top. 在情节提要中,将导航项添加到viewController并将条形按钮项移动到顶部显示的导航栏中。

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

相关问题 UITabBarController中“更多”视图控制器的自定义导航栏 - Custom navigation bar for the “More” View Controller in a UITabBarController 为UITabBarController子视图控制器设置相同的导航栏? - Set same navigation bar for UITabBarController child view controllers? 在子视图控制器中显示导航栏 - Show Navigation Bar in Child View Controller 尝试创建导航栏后退按钮到选项卡栏控制器视图 - Trying to create a Navigation Bar back button to a Tab Bar Controller view 从标签栏按钮将视图控制器推到导航控制器上 - Pushing a view controller onto a navigation controller from a tab bar button 从嵌套在UITabBarController中的导航控制器中推送视图控制器? - Pushing a View Controller from a Navigation Controller nested in a UITabBarController? 推入子视图后,在导航栏中更改后退按钮文本 - Changing back button text in navigation bar after the child view is pushed in 将导航栏中的按钮栏添加到Table View Controller-Obj C - Adding button bar from navigation to Table View Controller - Obj C iPhone:如何从视图控制器的导航栏中删除右键? - iPhone : How to remove right button from navigation bar in a view controller? 导航控制器栏按钮与嵌入容器视图交互 - interact the navigation controller bar button with embed container view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM