gpt4 book ai didi

ios - swift deinit 方法不调用

转载 作者:行者123 更新时间:2023-11-29 05:46:54 30 4
gpt4 key购买 nike

UIViewController deinit方法中未在ios swift4.2中调用

我已尝试使用以下代码在 popToViewcontroller 导航后导航到下一个 viewController 未调用 deinit 方法。

 let data = isSearchEnabled ? repository.filteredList[index] : repository.list[index]
let appDelegate = UIApplication.shared.delegate as! AppDelegate
(appDelegate.window?.rootViewController as! UITabBarController).tabBar.isHidden = true
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "AuctionDetailsViewController") as! AuctionDetailsViewController
viewController.auction = data.getAuctionData()
viewController.parentVC = self
parentNavigationController?.pushViewController(viewController, animated: true)

推送 View :

deinit {
print("AuctionDetailsViewController deallocated...")
}

上面的deinit方法应该在popToViewcontroller上调用

最佳答案

您需要了解 iOS 使用 ARC 进行的内存管理。您可以阅读此here

Deinit() 不会被调用,如果 viewcontoller...

holds the strong reference of an object(retain cycle)

you need to check and remove the unnecessary strong references to an object to avoid retail cycle

有通知观察者

you need to unregister an observer because the notification center retains the observer until you unregister it.

委托(delegate)的使用(持有它的强引用)

if view controller is confirming the protocol that delegate should be marked as weak.

上面提到的是阻止 View Controller dealloc和deinit永远不会被调用的一些要点。可能还有其他原因。

关于ios - swift deinit 方法不调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56053838/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com