如何以编程方式加载 UIViewController?
我正在尝试从代码加载 UIViewController 。我基本上创建了一个生成 .xib 文件的 UIViewController。我使用以下代码加载它:
testViewController = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
这可以工作,但显然(从我读到的内容来看)只有视图被保留并且控制器被释放(我已经测试过在 UIViewController 的 dealloc 方法中放置断点)。我需要保留 UIViewController 或以其他方式创建一个带有从 nib 文件加载的 UIView 的 UIViewController 。如何才能实现这一目标?
I'm trying to load a UIViewController from code. I basically created a UIViewController generating a .xib file. I load it with the following code:
testViewController = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
this works but apparently (from what I have read) only the view is kept and the controller is deallocated (something which I have tested putting a breakpoint in the UIViewController's dealloc method). I need to keep the UIViewController or otherwise, create a UIViewController with a UIView loaded from a nib file. How can this be achieved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定你的意思。你在那里做的事情是正确的。既然你已经分配了它,你还需要在某个时候向视图控制器发送一条释放语句,直到那时它不应该被释放。
在应用程序收到内存警告的特殊情况下,视图可能会被释放并设置为 nil,但我不确定这是否是您所读到的内容。
Not sure what you mean. What you're doing there is correct. Since you've allocated it, you also -need to send a release statement to the view controller at some point, till then it shouldn't be dealloc'ed.
A view might get released and set to nil under a special case where the application receives a memory warning, but I'm not sure if this was what you've read.