Geet
Geet

Reputation: 2437

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

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??

Upvotes: 0

Views: 450

Answers (4)

Abhishek Sharma
Abhishek Sharma

Reputation: 3283

try the following code

UINavigationController * navController = [[self.tabBarController viewControllers]objectAtIndex:[self.tabBarController selectedIndex]];
    navController.navigationItem.rightBarButtonItem = aBarButtonItem

Upvotes: 0

Geet
Geet

Reputation: 2437

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

  self.tabBarController.navigationItem.rightBarButtonItem=right;

I also Had to override this code in the second ViewCOntroller with

  self.tabBarController.navigationItem.rightBarButtonItem=nil;

Only then I was able to add and respond to the NavigationItems in the Navigation Bar

Upvotes: 1

Ashley Mills
Ashley Mills

Reputation: 53181

The navigationItem you're interested in is a property of your viewController, not the navigationController or tabBarController.

So if you try:

self.navigationItem.rightBarButtonItem = aBArButtonItem;

you'll have more success!

Upvotes: 0

Levi
Levi

Reputation: 7343

Instead of self.navigationController.navigationItem.rightBarButtonItem=aBArButtonItem; try self.navigationItem.rightBarButtonItem=aBArButtonItem;. This way you access the navigationItem from your view controller, not from the entire navigation controller

Upvotes: 0

Related Questions