Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

popTOViewController

I have a button named 'HOME'. In that button action I have the following code:

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

When I click this button my app crashes.

Changing the index from 1 to 2, then it pops the view perfectly.

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

My view sequence is Page1 --> Page2 --> Page3

I want to go from Page3 to Page1 but the app crashes. From Page3 to Page2 it works fine.

like image 872
Sam007 Avatar asked Apr 22 '11 07:04

Sam007


People also ask

How do I pop two viewControllers at a time in Swift?

There's also a setViewControllers(_:animated:) to include the pop animation. Alternatively you could find the second last view controller in the viewControllers array and then use popToViewController to avoid overwriting the entire view controller stack.


1 Answers

Try this.

Where I have written SeeMyScoresViewController you should write your View Controller class on which you have to go.(eg. Class of Home)

NSArray *viewControllers = [[self navigationController] viewControllers]; for( int i=0;i<[viewControllers count];i++){     id obj=[viewControllers objectAtIndex:i];     if([obj isKindOfClass:[SeeMyScoresViewController class]]){         [[self navigationController] popToViewController:obj animated:YES];         return;     } } 
like image 150
Gypsa Avatar answered Sep 22 '22 23:09

Gypsa