我正在使用一些自定義控制器轉換,它使用UINavigationController的delegate
屬性。如果我將它設置爲viewDidLoad()
,則self.navigationController?.delegate
會在推送後的某個點被取消分配。將其設置爲viewWillAppear()
的作品,但我想知道爲什麼該資源首先被取消分配,以及人們通常設置此屬性的位置。我應該在哪裏設置UINavigationController的委託屬性?
// 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的根控制器。 – GoldenJoe
我建議在代表值上設置一個觀察斷點,以確定誰將其設置回零。 – vacawama
我不擅長裝配。 – GoldenJoe