在viewWillDisappear方法可以檢查值isMovingFromParentViewController:
self.isMovingFromParentViewController()
它將返回Bool,它是一個布爾值,指示視圖控制器正在從其父項中移除。
更新時間:
作爲回答,我想你會需要自定義的執行回用自己的方法按鈕,可以跟蹤它。
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.hidesBackButton = true;
let backButton = UIBarButtonItem(title: "< Back", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
backButton.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "Chalkduster", size: 20)!], forState: UIControlState.Normal)
navigationItem.backBarButtonItem = backButton
backButton.addTarget(self, action: "backButtonMethod",forControlEvents:UIControlEvents.TouchUpInside)
[檢測當按下一個導航欄的「返回」按鈕]的可能的複製(http://stackoverflow.com/questions/8228411/detecting-when-the-back-button-is-pressed- on-a-navbar) –
嗨。這不是這個問題的重複,因爲我試圖找出哪個事件被調用,而不是視圖控制器被解僱的地方 – Lneuner
@Lneuner viewDidDisappear:和viewWillDisappear是視圖消失時調用的方法 – Smile