Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController title is not displayed?

Tags:

I have normal UIViewController ,inwhich I added UINavigationControllerDelegate,i added as following in willappear?but it did not work?

    [self.navigationController setNavigationBarHidden:NO animated:YES];     self.navigationController.navigationItem.title = @"hai"; 
like image 267
senthilM Avatar asked Jan 11 '10 07:01

senthilM


People also ask

What is a UINavigationController?

A container view controller that defines a stack-based scheme for navigating hierarchical content.

What is navigation stack in Swift?

What is a navigation stack? “A navigation controller object manages its child view controllers using an ordered array, known as the navigation stack. The first view controller in the array is the root view controller and represents the bottom of the stack.

What is navigation controller in xcode?

A navigation controller is a container view that can manage the navigation of hierarchical contents. The navigation controller manages the current displaying screen using the navigation stack.


2 Answers

You should set the title in the view controller you add to your navigation controller.

i.e. in the add view controller

- (void)viewDidLoad {     [super viewDidLoad];     self.title = @"My Title"; } 

or access the array of your viewcontrollers directly

        AddFriendViewController *addFriendsView = [[AddFriendViewController alloc] initWithNibName:@"AddFriendViewController" bundle:nil];         [self.navigationController pushViewController:addFriendsView animated:YES];         [[self.navigationController.viewControllers objectAtIndex:0] setTitle:@"myTitle"];         [addFriendsView release]; 
like image 62
Henrik P. Hessel Avatar answered Sep 27 '22 20:09

Henrik P. Hessel


Every view controller has a navigation item. You are changing the navigation item of the navigation controller... but that will never be seen unless the navigation controller was inside another navigation controller! Instead of

self.navigationController.navigationItem.title = @"hai"; 

you want

self.navigationItem.title = @"hai"; 

or, if your navigation item's title is nil, the navigation controller will use your view controller's title:

self.title = @"hai"; 

You should simply set the view title, which is used by both navigation bars and tab bars, unless you want to specify a different title for each of those for some reason.

like image 26
benzado Avatar answered Sep 27 '22 20:09

benzado