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?




titleis a property ofUIViewController.self.navigationControlleris aUINavigationControllerthat manages the stack of viewControllers that yourviewControlleris in.UINavigationControlleris a subclass ofUIViewController, soself.navigationController.titleis thetitleof theUINavigationController.self.navigationItem.title:So, in practice, you should set the
titleof yourViewControllers. iOS will copy this title to the navigation item or tab bar item and display this title on the Navigation Bar if yourViewControlleris 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 yourViewControlleris managed by aUITabBarController.