没有xib文件的alloc/init初始化的viewcontroller不调用viewDidUnload [英] viewDidUnload not called for alloc/init initialized viewcontroller with no xib file

查看:162
本文介绍了没有xib文件的alloc/init初始化的viewcontroller不调用viewDidUnload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我不使用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屋!

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