Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, u can implement this. This is a simple navigation in iOS using NavigationController. you have six viewControllers 1, 2, 3, 4, 5, 6.</p> <p>to do this: First create a NavigationController and initialize it with ViewController 1 (ie a root View Controller).</p> <p>Now your navigationController behaves like a stack which contains all ur pushed view controller. NavigationController is only push and pop ur view controllers.</p> <p>So, every time when u want to navigation first check ur viewController is inside navigationController stack or not. If it is already in stack then pop to that controller, if not then push the same view controller. for this use following:</p> <p>In case ViewController3</p> <pre><code>-(void)popToSelectedViewController { NSArray *vc=[self.navigationController viewControllers]; ViewController3 *vc3=nil; for (int i=0; i&lt;[vc count]; i++) { UIViewController *tempVC=[vc objectAtIndex:i]; if([tempVC isKindOfClass:[ViewController3 class]]) { vc=[vc objectAtIndex:i]; break; } } if(vc3) { //If exists inside stack the pop [self.navigationController popToViewController:vc3 animated:YES]; } else { //If not exists inside stack push ViewController3 ViewController3 *vc3New= [[ViewController3 alloc]initWithNibName:@"ViewController3" bundle:nil]; [self.navigationController pushViewController:vc3New animated:YES]; [vc3New release]; } } </code></pre> <p>For initializing ur ViewController1 with navigationController:</p> <p><strong>if using storyboard</strong> Embed ur initialViewController(ie viewController3) with UINavigationController. for this:</p> <p>Step1: open storyboard, and select ur initialViewController(ie viewController3).</p> <p>Step2: Go to Editor in menu -> Choose Embed In -> Select UINavigationController. this creates a navigationcontroller and initializes with viewController3 as rootViewController.</p> <p><strong>if not using storyboard</strong> make property of vc3 (ViewController3) and applicationNavigationController (UINavigationController) in .h</p> <p>and in .m:</p> <p>got method "application... didFinishedLaunching...." in appDelegate and write:</p> <pre><code>self.vc3=[[ViewController3 alloc]initWithNibName:@"ViewController3" bundle:nil]; self.applicationNavigationController=[[UINavigationController alloc] initWithRootViewController:self.vc3]; self.window.rootViewController=self.applicationNavigationController; [self.window makeKeyAndVisible]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload