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.
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.
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; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With