NavigationController.viewControllers Works differently in iOS 8.2

In my project, I used the code to handle the back button as follows.

NSMutableArray *VCs = [NSMutableArray arrayWithArray: self.navigationController.viewControllers]; if ([[VCs objectAtIndex:[VCs count] - 2] isKindOfClass:[LoginViewController class]]) { [VCs removeObjectAtIndex:[VCs count] - 2]; [VCs removeObjectAtIndex:[VCs count] - 2]; } [self.navigationController setViewControllers: VCs]; 

In iOS 7, I get the desired result. But for iOS version 8.2, the value in the VC of the changed arrays is only the current one or topViewController on the stack. But the back button will take you to all previous view controllers. But not one of them is present there in the navigation stack. Are there any changes to navigation handling in ios8?

I want to remove the login screen view manager from the stack so that when I click the back button, it will not return to the login screen. I encountered this problem only in iOS 8.2 (maybe in iOS 8 and above). What could be the problem?

Edit:

In prepareForSegue:, I use the following code:

 if([[segue identifier] isEqualToString:@"mediaDetailSegue1"]) { MovieDetailViewController *movieDetail; if(isIOS8SystemVersion) { movieDetail = ([[segue destinationViewController]viewControllers][0]); } else { movieDetail = [segue destinationViewController]; } movieDetail.videoData = [_mediaContentArray objectAtIndex:selectedIndex]; } 

therefore, for iOS versions exceeding 8, the code

  movieDetail = ([[segue destinationViewController]viewControllers][0]); 

. I think this is causing the problem. Am I doing it wrong?

+5
source share
2 answers

I have a reason why my navigation stack has only one viewController. In iOS8 and above, if we make a segue from the viewController to the second viewController via the navigationController of the second VC, then the Stack navigation of the second VC will contain only the topViewController.

I tried to create a sample project. If the segue from VC to the second VC is direct, then the VC2 navigation stack will contain VC1 and VC2. If the segue passes through the VC2 navigation controller, then the VC2 navigation stack will only contain VC2. Strict iOS8 behavior.

In both cases, the application behaves similarly in ios 7. I don’t know why it behaves strangely in ios8

+1
source

I am trying to do the same with iOS 8.2. self.navigationController.viewControllers returns all view controllers on the stack. There are no such problems. I'm not sure why you came across such a problem.

Try using this code. It works great for me.

 NSMutableArray *VCs = [NSMutableArray arrayWithArray: self.navigationController.viewControllers]; for(int i = 0; i < VCs.count; i++) { UIViewController *vc = VCs[i]; if ( [vc isKindOfClass:[LoginViewController class]]) { [VCs removeObjectAtIndex:i]; } [self.navigationController setViewControllers: VCs]; 
0
source

All Articles