在每个UIViewController中,我通过一个简单的print语句获得了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中,其中的特定代码段是in...strange!
为什么会这样呢?
发布于 2020-07-03 20:16:06
嗯,UITabBarController和预期的一样工作得很好。也许你走错了路。如果您想观察通知,可以在UITabBarController类中观察它,而不是在UITabBarController内部的ViewController中观察它。有关更多信息,请参阅UITabBarController的苹果文档。
https://stackoverflow.com/questions/62714393
复制相似问题