Monotouch:我必须处置视图吗?

发布于 2025-01-03 02:07:09 字数 232 浏览 2 评论 0原文

在我的 AppDelegate 中,我有一个名为 LoggedOn 的静态事件。

我的父视图控制器推送客户端视图控制器。我的客户端视图控制器将委托添加到 AppDelegate.LoggedOn 事件。

当我弹出客户端视图控制器时,LoggedOn 事件的侦听器仍在侦听.. emmmmm ...我需要将其丢弃还是其他什么?

我以为当我弹出它时整个客户端视图就被处理掉了?

谢谢! 莫乔

In my AppDelegate, I have a static event called LoggedOn.

My parent viewcontroller pushes a client viewcontroller.My client viewcontroller adds a delegate to the AppDelegate.LoggedOn event.

When I pop the client viewcontroller, the listner for the LoggedOn event is still listening .. emmmmm ... do I need to like dispose it or something?

I thought the whole client view was disposed when I pop'ed it?

Thanks!
Mojo

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

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

发布评论

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

评论(1

掌心的温暖 2025-01-10 02:07:09

最好将 EventHandler 处理为全局事件,例如您拥有的 LoggedOn 事件。这些称为强引用,会阻止包含委托的 ViewController 被垃圾回收。

我会在 ClientViewController 中做这样的事情:

public override void Dispose(bool disposing) 
{
    base.Dispose(disposing);

    if(disposing) {
        AppDelegate.LoggedOn -= Handle_LoggedOn;
    }
}

It's best to dispose of EventHandlers to global events like the LoggedOn event you have. These are called strong references and would prevent the ViewController that contains the delegate from being garbage collected.

I would do something like this in the ClientViewController:

public override void Dispose(bool disposing) 
{
    base.Dispose(disposing);

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