有没有办法强制 UIView 释放子视图?

发布于 2024-10-05 04:31:09 字数 739 浏览 3 评论 0原文

假设我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深巷少女 2024-10-12 04:31:09

要强制您的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].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文