没有xib文件的alloc/init初始化的viewcontroller不调用viewDidUnload [英] viewDidUnload not called for alloc/init initialized viewcontroller with no xib file
问题描述
当我不使用xib并通过Simulator模拟任何iOS版本的内存警告时,为什么不调用viewDidUnload
方法,为什么使用alloc/init初始化我的ViewController
?似乎从未调用过此方法.
Why isn't viewDidUnload
method called, when I'm not using xib and use alloc/init to initialize my ViewController
when i simulate memory warning for any iOS version via Simulator? It seems as if this method is never called.
如果我通过带有xib文件的alloc/initWithNibName创建控制器,则成功调用了viewDidUnload方法. 为什么会发生呢?是否所有视图控制器都需要xib文件才能正常处理内存警告?
If I create controller via alloc/initWithNibName with xib file, viewDidUnload method successfully called. Why does it happend? Does xib file is reqired for all viewcontrollers to normal handling of memory warnings?
推荐答案
我解决了我的问题. 我没有xib的实现只需要添加以下代码:
I solve my problem. My implementation with no xib just need to add this code:
- (void) loadView {
UIView * myView = [[[UIView alloc] init] autorelease];
self.view = myView;
}
这篇关于没有xib文件的alloc/init初始化的viewcontroller不调用viewDidUnload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!