总是调用dealloc吗?即使您滑动关闭应用程序? [英] Is dealloc always called? Even when you swipe close an app?

查看:48
本文介绍了总是调用dealloc吗?即使您滑动关闭应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在iOS版Objective-C中关闭ViewController时是否总是调用dealloc.我已经做了一些测试,看起来像是.滑动关闭应用程序时,没有任何日志记录.我认为,如果您完全关闭应用程序,那么XCode可能不会记录任何事情.

I wonder if dealloc is always called when you close a ViewController in Objective-C for iOS. I've done some tests and it seems like it. Except I don't get any logs when I swipe close the application. I figured that maybe XCode doesn't log things if you fully close the app like that.

我想知道这是因为当其中一个ViewController关闭时我正在发送分析数据,我有点想知道是否总是调用dealloc或是否有更好的方法.

The reason I wonder this is because I'm sending analytic data when one of the ViewControllers closes and I kinda need to know if dealloc is always called or if there's any better way doing this.

推荐答案

在视图控制器(或几乎所有类)将调用 dealloc 时未定义.用于发送分析.

It's not defined when dealloc will be called for a view controller (or pretty much any class), therefore don't use it for sending analytics.

改为使用 viewDidDisappear ,在删除视图控制器时可以依靠它来调用.

Use viewDidDisappear instead, which you can rely on to be called when the view controller has been removed.

这篇关于总是调用dealloc吗?即使您滑动关闭应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆