Friday, November 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];
}

No comments:

Post a Comment