[英]self.navigationController is nil second time ViewController is loaded
I have a delegate/handler that i have implemented on my UIViewControllers to handle timeouts to the a remote webservice. 我有一个委托/处理程序,我已经在我的UIViewControllers上实现了处理远程Web服务的超时。 When a request is made to my webservice, and a timeout http code is returned, the delegate is called and performs the following:
当向我的webservice发出请求并返回超时http代码时,将调用该委托并执行以下操作:
UINavigationController *navController = self.navigationController;
if (navController) {
[navController popToRootViewControllerAnimated:YES];
} else {
NSLog(@"navController is null/nil");
}
If I do the following steps, navController
is instantiated correctly and the popToRootViewController
action occurs. 如果我执行以下步骤,
navController
将正确实例化并发生popToRootViewController
操作。
Now, if i do the following steps, the else clause in the above code block is triggered because for some reasons navController isn't being set correctly: 现在,如果我执行以下步骤,则会触发上述代码块中的else子句,因为由于某些原因导航器未正确设置:
My question is: why when i load a ViewController for the second time, does self.navigationController return null? 我的问题是:为什么当我第二次加载ViewController时,self.navigationController是否返回null?
The call stack in the above example should look like this: NavigationController -> CustomLoginViewController -> CustomMenuViewController -> CustomSubMenuViewController
上面示例中的调用堆栈应如下所示:
NavigationController -> CustomLoginViewController -> CustomMenuViewController -> CustomSubMenuViewController
Thanks 谢谢
UPDATE: Still haven't made any progress on this issue! 更新:在这个问题上仍然没有取得任何进展!
嘿,这可能听起来很基本,但是,你是否正确分配了Navbar对象,也许你可以尝试将其属性设置为强大。也许这样它就会在时间之前被释放。
I think you might have already resolved this but i encountered the exact same thing. 我想你可能已经解决了这个问题,但我遇到了同样的事情。 And I think we might be doing the exact same thing like using facebook for login.
而且我认为我们可能会像使用Facebook登录一样完全一样。 Anyway for some one else in the future this might be useful.
无论如何,对于未来的其他人来说,这可能是有用的。 The issue that i had that i was re allocating the UINavigationController again when coming back from background on a failure condition.
我遇到的问题是在故障情况下从后台返回时再次重新分配UINavigationController。
So what you can do is try to put a breakpoint around the place where you initialise your rootViewController for the UiNavigationController. 所以你可以做的是尝试在初始化uiNavigationController的rootViewController的地方放置一个断点。
[[UINavigationController alloc]
initWithRootViewController:viewController]; and make sure that you do re-initailise your UINavigationController if you have already done it.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.