iOS开发:[[self navigationController] viewControllers]的原因是什么?会回来没有? [英] iOS Development: What are some reasons that [[self navigationController] viewControllers]; would return nil?

查看:476
本文介绍了iOS开发:[[self navigationController] viewControllers]的原因是什么?会回来没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下语句返回nil ...

the following statement is returning an nil...

NSArray *viewControllersInNavStack = [[self navigationController] viewControllers];

这个语句是在一个视图控制器中调用的,它在导航堆栈中大约有四层,所以我不明白它是如何或为什么会返回零。你的想法?

and this statement is being called in a view controller that's about four levels deep in the navigation stack, so I don't understand how or why it would ever return nil. Your thoughts?

非常感谢你的智慧!

推荐答案

我发现了问题。响应ApplicationWillResignActive通知正在调用此语句。好吧,堆栈上方的其他视图控制器之一也在监听相同的通知,并且其处理程序从堆栈中弹出视图控制器,以及堆栈中更深层次的所有其他视图控制器,包括执行上面代码的那个。因此,在执行代码时,其视图控制器不再在堆栈中。

I found the problem. This statement was being called in response to an ApplicationWillResignActive notification. Well, one of the other view controllers higher up the stack was also listening for the same notification and its handler popped that view controller off the stack, along with all the other view controller deeper down the stack, including the one executed the code above. Therefor, by the time the code was executed, its view controller was no longer on the stack.

这篇关于iOS开发:[[self navigationController] viewControllers]的原因是什么?会回来没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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