[英]Unable to add Navigation Items on Navigation bar
I have Used a Navigation controller, IN my application within a TAbbar controller, the problem I am facing is I am unable to add Navigation bar Items to the navigation bar of a particular controller 我已经使用了导航控制器,在TAbbar控制器中的应用程序中,我面临的问题是我无法将导航栏项添加到特定控制器的导航栏中
when I do 当我做
self.navigationCOntroller.navigationItem.rightBarButtonItem=aBArButtonItem;
Nothing is shown 没有显示
When I do 当我做
self.tabController.navigationController.navigationItem.rightBArButtonItem=aBArButtonItem
then the same item is being added to all the viewCOntrollers in the Tabbarcontroller, I wan to display different bar button Items on different Controllers, Any Ideas how I can Achieve this?? 然后将同一项目添加到Tabbarcontroller中的所有viewCOntrollers中,我要在不同的Controller上显示不同的条形按钮项目,我有什么想法可以实现这一目标?
I finally figured it out, I wasnt able to add any navigation Item because the TabbarCOntroller was the Container View, the following Code Helped Me out 我终于想通了,因为TabbarCOntroller是容器视图,所以我无法添加任何导航项,以下代码帮助了我
self.tabBarController.navigationItem.rightBarButtonItem=right;
I also Had to override this code in the second ViewCOntroller with 我还不得不用第二个ViewCOntroller覆盖此代码
self.tabBarController.navigationItem.rightBarButtonItem=nil;
Only then I was able to add and respond to the NavigationItems in the Navigation Bar 只有这样,我才能在导航栏中添加并响应NavigationItems
try the following code
试试下面的code
UINavigationController * navController = [[self.tabBarController viewControllers]objectAtIndex:[self.tabBarController selectedIndex]];
navController.navigationItem.rightBarButtonItem = aBarButtonItem
Instead of self.navigationController.navigationItem.rightBarButtonItem=aBArButtonItem;
代替self.navigationController.navigationItem.rightBarButtonItem=aBArButtonItem;
try self.navigationItem.rightBarButtonItem=aBArButtonItem;
尝试self.navigationItem.rightBarButtonItem=aBArButtonItem;
. 。 This way you access the navigationItem
from your view controller, not from the entire navigation controller 这样,您访问navigationItem
从您的视图控制器,而不是从整个导航控制器
The navigationItem
you're interested in is a property of your viewController
, not the navigationController
or tabBarController
. 该navigationItem
你感兴趣的是你的财产viewController
,而不是navigationController
或tabBarController
。
So if you try: 因此,如果您尝试:
self.navigationItem.rightBarButtonItem = aBArButtonItem;
you'll have more success! 您将获得更大的成功!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.