Narendra Pandey February 2016

How t go at specific page in ios

I know this question have been answered before, but i have difficulty to pop on specific page in ios. As i have already tried many times. as i have build 4 pages and and want to move last page to second page. with the help of this code i have gone through first page

[self.navigationController popToRootViewControllerAnimated:YES];

and with the help of this page i have gone to 3rd page.

[self.navigationController popViewControllerAnimated:YES];

but for second page i have written this code but it's not working

ViewPage2 *ptwo=[[ViewPage2 alloc] initWithNibName:@"ViewPage2" bundle:nil];
[self.navigationController popToViewController:ptwo animated:YES];

Answers


NickCatib February 2016

It is because you create new view controller which is not in the stack. What you should do is following:

for (UIViewController *vc in self.navigationController.viewControllers) {
    if ( [vc isKindOfClass:ViewPage2]){
        [self.navigationController popToViewController:vc animated:true];
        return; //optional
    }
}


MS. February 2016

Try with this

ViewPage2 *ptwo;

for (UIViewController *vc in self.navigationController.viewControllers) {

    if ([vc isKindOfClass:[ViewPage2 class]]) {

        ptwo = (ViewPage2 *)vc;
        break;
    }
}

[self.navigationController popToViewController:ptwo animated:true];

Thanks.


Uma Madhavi February 2016

Try this one

for (UIViewController *controller in self.navigationController.viewControllers) {

    //Do not forget to import YourViewController.h
    if ([controller isKindOfClass:[ViewController class]]) {

        [self.navigationController popToViewController:controller
                                              animated:YES];
        break;
    }
}


Shravan February 2016

you can try doing this

first import the ViewController on which page u want to go. like

#import ViewController.h

Then u can do the following

instantiate the class

ViewController *controller = [[ViewController alloc ] init];
[self.navigationController pushViewController:controller animated:YES]; 

or u can do popToViewController too


Bharath Raj February 2016

Here is the simple answer:

     NSArray *arr = [self.navigationController viewControllers];
                         [self.navigationController popToViewController:[arr objectAtIndex:0] animated:YES];

In place of,

[arr objectAtIndex:0]

here you can give index of specified view controller that you need to pop.

Post Status

Asked in February 2016
Viewed 3,874 times
Voted 10
Answered 5 times

Search




Leave an answer