【问题标题】:UITabBarController and dismissUITabBarController 和解雇
【发布时间】:2020-10-24 02:50:12
【问题描述】:

在每个 UIViewController 中,我都获得了带有简单打印语句的 deinit 函数,该语句告诉我该特定 UIViewController 何时从内存中删除。

deinit {
    print("VIEWCONTROLLER DELETED FROM MEMORY")
}

但是,作为 UITabBarController 一部分的所有 UIViewController 将永远不会调用 deinit,我也永远不会在控制台中看到 print 语句。

除此之外:

里面的代码...

NotificationCenter.default.addObserver(forName: UIApplication.didChangeStatusBarOrientationNotification, object: nil, queue: OperationQueue.main) { (notification) in


           print("Device rotated")
        }

... 也将在其他选项卡上调用。因此,当设备从横向切换到纵向时,即使我不在特定代码所在的 UIViewcontroller 中,上述闭包内的所有代码都将被执行......奇怪!

这是为什么呢?

【问题讨论】:

    标签: memory uiviewcontroller uitabbarcontroller dismiss


    【解决方案1】:

    嗯,UITabBarController 工作正常。可能是你走错了路。如果要观察通知,可以在 UITabBarController 类中观察它,而不是在 UITabBarController 内部的 ViewController 中观察它。更多信息可以浏览UITabBarController的苹果文档。

    【讨论】:

    • 好的,但是对于属于 UITabBarController 的特定 UIViewControllers,通知任务是不同的。所以我需要将通知观察者放在每个 UIViewController 中——或者我错了吗?
    • 您可以使用 UITabBarControllers 类对象 selectedViewController 执行此任务,并且可以调用方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 2013-03-25
    相关资源
    最近更新 更多