I would like to add title to my UIViewController:
I have tried
self.navigationController.navigationItem.title
self.navigationController.title
self.title
Sometimes, solution 1 work, sometimes solution 2 work, sometimes solution 3 works.
Can any expert tell me the different between them?
title
is a property ofUIViewController
.self.navigationController
is aUINavigationController
that manages the stack of viewControllers that yourviewController
is in.UINavigationController
is a subclass ofUIViewController
, soself.navigationController.title
is thetitle
of theUINavigationController
.self.navigationItem.title
:So, in practice, you should set the
title
of yourViewController
s. iOS will copy this title to the navigation item or tab bar item and display this title on the Navigation Bar if yourViewController
is managed by aUINavigationController
, it will use that text for the Back Button when you push to anotherViewController
, and it will display it in the tab bar if yourViewController
is managed by aUITabBarController
.