tags:

views:

1647

answers:

3

What is the purpose of the title property of UIViewController, can't the title already be set with navigationItem.title ?

Both seem to work, I'm just wondering why there's this seemingly duplicated functionality.

A: 

When you set navigationItem.title you are setting the title of the navigation bar on the top of the view. This is important when you push a new view controller because the title of the previous view (as set by navigationItem.title) will be the text of the back button. Further, if your project does not have a navigation bar, navigationItem.title will not work.

Apple gives the following description for the title property of UIViewController.

A localized string that represents the view that this controller manages.

zPesk
+1  A: 

The title of a view controller is both a convention and a convenience for you as a programmer. Calling...

self.title = @"Some Title";

or

[self setTitle:@"Some Title"];

ensures that any object (like the navigation bar) that needs to retrieve the title of your view controller can do so. Using navigationItem.title will allow you to over-ride this title as needed but it may be consider more "stylish" to set the title of your controller instead.

IMO you can do either but the former will save you some typing ;-)

Cheers-

J.Biard
A: 

UIViewController has the title property. in navigationItem and tabBarItem both override the title property. so if we have application with tabbar and navigationcontroller.and setting self.title=@"somethng" will set that title to both navigationTitle and tabBartitle.

pawan.mangal