Search This Blog

Nov 19, 2010

How to popToViewController to a particular Controller or index value of that Controller.

This code is used to popToViewController to the index value of a particular Controller or popToViewController to the Home Screen of your Application.


-(IBAction)btnHome_Clicked:(id)sender{
   
    NSInteger index = -1;
    YourAppicationAppDelegate *appDelegate = (YourAppicationAppDelegate *)[[UIApplication sharedApplication]delegate];
    UINavigationController *navigationController = [appDelegate navigationController];
    NSArray* arr = [[NSArray alloc] initWithArray:navigationController.viewControllers];
    for(int i=0 ; i<[arr count] ; i++)
    {
        if([[arr objectAtIndex:i] isKindOfClass:NSClassFromString(@"UIHomeViewController")])
        {
            index = i;
        }       
    }
    [self.navigationController popToViewController:[arr objectAtIndex:index] animated:YES];
}

3 comments:

  1. there is great tutorial for the german developer community:


    http://bedifferently.wordpress.com/2012/01/15/xcode-4-tutorial-uinavigationcontroller/

    ReplyDelete
  2. [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];

    You could also replace iterating through the array with this. Substitute your index as needed.

    ReplyDelete