I will learn about UINavigationController
and UIViewController
s. Here is a simple application that I am creating. Please note that I am using ARC.
My application has a navigation controller and two view controllers (call them FirstViewController
and SecondViewController
). When the application starts, the navigation controller pushes FirstViewController
onto the stack.
In FirstViewController
I have a button that clicks SecondViewController when touched. Here is the code.
FirstViewController.m
-(IBAction)pushSecondViewController { SecondViewController *secondViewController = [SecondViewController alloc]init]; [self.navigationController pushViewController:secondViewController animated:YES]; }
In the second view controller, I have a button that pops the current view controller from the stack.
SecondViewController.m
-(IBAction)popViewController { [self.navigationController popViewControllerAnimated:YES]; }
So far so good. Here are my questions:
Does navController check an existing SecondNavigationController instance, and if one does not exist, does it create a new one?
If not, should singleton be used to ensure that only one instance is created and reused instead of creating a new instance each time the button that clicks the SeconViewController
?
ihodo source share