Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigationController.viewControllers Works differently in iOS 8.2

In my project, I was using some 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 am getting the desired result. But for iOS version 8.2, the value in the mutable array VCs is only the current or topViewController in the stack. But the back button will navigate you to all the previous viewcontrollers. But none of them is present there in the navigation stack.Is there any change in the navigation handling in ios8?

I want to delete the login screen viewcontroller from the stack so that on clicking the back button,it will not go back to the login screen. I am facing this issue in iOS 8.2 only (may in iOS 8 and above). What can be the issue?

Edit:

In the prepareForSegue:, I am using 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];
    }

so for iOS versions greater than 8,the code

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

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

like image 623
abhimuralidharan Avatar asked Nov 10 '22 16:11

abhimuralidharan


1 Answers

I got the reason why my navigation Stack is having only one viewController. In iOS8 and above,if we make a segue from a viewController to a second viewController through the navigationController of the second VC,then the navigationStack of the second VC will contain only the topViewController.

I tried creating a sample project.If the segue is from the VC to second VC directly,then the navigation stack of VC2 will contain VC1 and VC2.If the segue is through the navigation controller of VC2,then the navigation stack of VC2 will contain VC2 only.Strange behaviour of iOS8.

IN both these cases,the app behaves the similar in ios 7.Dont know why it behaves strange in ios8

like image 144
abhimuralidharan Avatar answered Nov 14 '22 22:11

abhimuralidharan