【问题标题】:swift deinit method not working when UIView is removed from memory从内存中删除 UIView 时,快速 deinit 方法不起作用
【发布时间】:2016-07-13 14:14:04
【问题描述】:

Swift 中,当任何UIViewController 从内存中删除时,ARC 正在调用deinit,但如果从内存中删除任何UIView,则不会调用它。

例如

如果 UIViewControllerdeinit 工作得很好

class MusicPlayerUIViewController: UIViewController,UITableViewDelegate,UITableViewDataSource
    {
    deinit
        {
            APP_DELEGATE.RemovePlayerContents()
        }
    }

但如果UIViewdeinit 不起作用

class MusicPlayerView: UIView,UITableViewDelegate,UITableViewDataSource
{
deinit
    {
        APP_DELEGATE.RemovePlayerContents()
    }
}

任何想法。

【问题讨论】:

  • 您确定要发布此视图吗?
  • 你有没有得到答案 - 为什么 UIView 上的 deinit 方法没有被调用?

标签: swift uiview uiviewcontroller deinit


【解决方案1】:

父 ViewController 可以容纳你的 UIView。您必须将一个属性设置为 nil,该属性将您的 UIView 存储在父级 UIViewController 中以发布 uiview。

或者覆盖 removeFromSuperview() 并将您的 deinit 代码放入其中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 2014-02-13
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2018-03-15
    相关资源
    最近更新 更多