有没有办法强制 UIView 释放子视图?
假设我将 UIViewController 传递给 UINavigationController,如下所示:
SettingsViewController *settingsRootView = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
SettingsNavigationController *settingsView = [[SettingsNavigationController alloc] initWithRootViewController:settingsRootView];
[settingsRootView release];
[self presentModalViewController:settingsView animated:YES];
[settingsView release];
我释放了原始 UIViewController settingsRootView
上的保留,但 settingsView
保留了它的保留。当我关闭 settingsView
时,它应该释放自身及其所有子级,但由于某种原因,它没有释放。有没有办法告诉我的主应用程序视图它已使用 settingsView
完成,以强制我的主视图释放 settingsView
及其所有子视图?
Say I pass a UIViewController to a UINavigationController like so:
SettingsViewController *settingsRootView = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
SettingsNavigationController *settingsView = [[SettingsNavigationController alloc] initWithRootViewController:settingsRootView];
[settingsRootView release];
[self presentModalViewController:settingsView animated:YES];
[settingsView release];
I release my retain on the original UIViewController, settingsRootView
, but settingsView
holds a retain on it. When I dismiss settingsView
, it should release itself and all of its children, but for some reason it's not. Is there a way to tell my main application view that it's done with settingsView
to force my main view to release settingsView
and all of its subviews?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要强制您的settingsView释放它正在管理的任何控制器,请调用settingsView.viewControllers = nil。
但这应该在发布 settingsView 时自动发生。在 settingsView 的 dealloc 方法中放置一个断点,以确保它被释放。确保 dealloc 正在调用 [super dealloc]。
To force your settingsView to release any controllers it is managing, call settingsView.viewControllers = nil.
But this should happen automatically when settingsView is released. Place a breakpoint in the dealloc method of your settingsView to ensure it is being released. Make sure dealloc is calling [super dealloc].