Ios – UIViewController Title attribute in Storyboard

cocoa-touchiosobjective c

I am setting the title field of a UIViewController via Interface Builder/Storyboard:
enter image description here

This view controller is nested in a UINavigationController which in turn is nested within a UITabBarController. When I run the app, I my navigation item has no title, neither does the tab bar item.

If I explicitly set the view controller's navigation item's title, and also it's tab bar item's title in interface builder, then it works just fine.

I am wondering:

a)If I am not using Storyboard but just regular xibs, setting the title of a view controller implicitly sets the navigation items' title as well as the tab bar item's title. But it's not the same storyboard. Is this the intended behaviour?

b) What is then the purpose of the view controller's title (in Storyboard)? it seems to have no effect.

Thanks!

Best Answer

You can set the title of the UINavigationBar in Storyboard by double clicking the actual navigationBar and typing in a title right there. This only sets the title for the UINavigationBar.

Setting the title in code offers some different possibilities.

self.title = @"Your title"; will set the title of a navigationBar and also cause the title to cascade down to a UITabBarItem, if present.

self.navigationItem.title = @"Your title"; will only set the title of the navigationBar, assuming a UINavigationController is present, and NOT affect a UITabBarItem.

self.navigationController.title = @"Your title"; will set the title of a UITabBarItem but NOT the UINavigationBar.