navigationController.viewControllers 在 iOS 8.2 中的工作方式不同 [英] navigationController.viewControllers Works differently in iOS 8.2

查看:38
本文介绍了navigationController.viewControllers 在 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];

在 iOS 7 中,我得到了想要的结果.但是对于 iOS 8.2 版本,可变数组 VCs 中的值只是栈中的 current 或 topViewController.但是后退按钮会将您导航到所有以前的视图控制器.但是导航堆栈中没有它们.ios8 中的导航处理有什么变化吗?

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?

我想从堆栈中删除登录屏幕视图控制器,以便在单击后退按钮时不会返回到登录屏幕.我仅在 iOS 8.2 中遇到此问题(可能在 iOS 8 及更高版本中).可能是什么问题?

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?

prepareForSegue: 中,我使用以下代码:

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];
    }

所以对于大于 8 的 iOS 版本,代码

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?

推荐答案

我明白了为什么我的导航堆栈只有一个 viewController 的原因.在iOS8及更高版本中,如果我们通过第二个VC的navigationController从一个viewController转为第二个viewController,那么第二个VC的navigationStack将只包含topViewController.

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.

我尝试创建一个示例项目.如果segue是从VC直接到第二个VC,那么VC2的导航栈将包含VC1和VC2.如果segue是通过VC2的导航控制器,那么VC2 将只包含 VC2.iOS8 的奇怪行为.

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.

在这两种情况下,应用程序在 ios 7 中的行为相似.不知道为什么它在 ios8 中的行为很奇怪

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

这篇关于navigationController.viewControllers 在 iOS 8.2 中的工作方式不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆