【发布时间】:2017-06-04 23:16:21
【问题描述】:
我正在处理一些自定义控制器转换,它们利用 UINavigationController 的 delegate 属性。如果我在viewDidLoad() 中设置它,self.navigationController?.delegate 在推送后的某个时间点会被释放。在viewWillAppear() 中设置它是可行的,但我想知道为什么该属性首先会被释放,以及人们通常在哪里设置此属性。
// The first time you push, it will work correctly, and the delegate function below is called. After you pop back to this controller, delegate is nil (has been deallocated)
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.delegate = self
}
// Brute force works
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.delegate = self
}
func navigationController(_ navigationController: UINavigationController,
animationControllerFor operation: UINavigationControllerOperation,
from fromVC: UIViewController,
to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning?
{
if operation == .push {
return WTPPushAnimator()
}
if operation == .pop {
return WTPPopAnimator()
}
return nil;
}
【问题讨论】:
-
还是没有答案吗?我看到了关闭的问题,它不会被释放,但委托方法没有触发:(
-
似乎当你调用 navigationController?.pushViewController(vc, animated: false) 而不是 navigationController?.pushViewController(vc, animated: true) 时会发生这种情况
标签: ios swift uiviewcontroller uinavigationcontroller