UIViewController 被保留

发布于 2024-12-29 01:46:36 字数 234 浏览 0 评论 0原文

在我的应用程序中,我有三个 UIViewController 对象。

V1-> V2-> V3

当我从 V2 移动到 V3 时,我使用推送,从 V3 移动到 V2 使用弹出。但不知何故,V3 的对象被保留了。

我认为当我们执行 pop 操作时,堆栈中的所有对象(V3 对象)都会被删除。然而,在本例中并没有发生这种情况。

有人可以建议如何解决这个问题吗?

谢谢

In my application, I have three UIViewController objects.

V1 -> V2 -> V3

When I move from V2 to V3, I'm using push and from V3 to V2 using pop. But somehow, the objects of V3 are being retained.

I thought that when we do pop, all the objects - V3 objects - from the stack are removed. However that's not happening in this case.

Can someone suggest how to resolve this issue?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

绅士风度i 2025-01-05 01:46:36
 V3 *v3 = [[[V3 alloc] initWithNibName:@"V3" bundle:nil] autorelease]; 
             [self.navigationController pushViewController: v3 animated:YES];

这是在导航栏中推送控制器的标准方法。

要么您缺少 v3 上的自动释放或释放,要么您将其保留在其他地方。

 V3 *v3 = [[[V3 alloc] initWithNibName:@"V3" bundle:nil] autorelease]; 
             [self.navigationController pushViewController: v3 animated:YES];

this is the standard way of pushing controller in the navigation bar..

Either you are missing the autorelease or release on the v3 or you are retaining it somewhere else..

独孤求败 2025-01-05 01:46:36

正如您使用导航控制器推动视图控制器一样,在下面添加一行以释放它。

向我们展示一些您实际在做什么的代码。那么我们可以准确地告诉你。

Just as you push the view controller using the navigation controller add a line below to release it.

Show us some code of what actually your are doing. Then we can tell you exactly.

若无相欠,怎会相见 2025-01-05 01:46:36

除了 Shubhank 所说的之外,请确保在 UIViewController 本身内的这些方法中平衡保留和释放:

viewDidLoad & viewDidUnload

viewWillAppear: & viewWillDisappear:

另外,请确保您在 dealloc 方法中释放带有“retain”或“copy”属性的任何属性。

只要您在 dealloc 中正确清理所有内容,并且 UIViewController 本身的保留/释放计数是平衡的(请参阅 Shubhank 的答案),您就不会有问题,并且所有内容都会按预期释放。

In addition to what Shubhank said, make sure you balance out the retains and releases in these methods within the UIViewController itself:

viewDidLoad & viewDidUnload

viewWillAppear: & viewWillDisappear:

Also make sure that you are releasing any property with a "retain" or "copy" attribute in your dealloc method.

As long as you are cleaning up everything properly in dealloc, and your retain/release count for the UIViewController itself is balanced (see Shubhank's answer), you will have no problem and everything will get released as expected.

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