Member-only story
UINavigationController iOS
UINavigationController is used to form a tree-like hierarchy of view controllers, which is known as a navigation stack.
From developers perspective:
You can connect independently made controller and get all the benefits of a free hierarchy manager and common UI presenter gratis. UINavigationController animates the transition to new controllers and provides the back functionality for you automatically. UINavigationControlleralso gives access to all the other controllers in the navigation stack which can help access to some functionality or data.
From user’s perspective:
UINavigationController helps to remember where user is at the moment (navigation bar title) and how he can go back (embedded back button) to one of the previous screens.
Embed a view controller in a navigation controller programmatically
//Swiftlet viewController = UIViewController()
let navigationController = UINavigationController(rootViewController: viewController)//Objective-CUIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:viewController];
Popping in a Navigation Controller
To previous view controller
To pop back to the previous page you can do this:
Swift
navigationController?.popViewControllerAnimated(true)
Objective-C
[self.navigationController popViewControllerAnimated:YES];
To root view controller
To pop to the root of the navigation stack, you can do this:
Swift
navigationController?.popToRootViewControllerAnimated(true)
Objective C
[self.navigationController popToRootViewControllerAnimated:YES];