2017-07-19 75 views
0

我正在從事xamarin.ios。我想在用戶點擊頂部的後退導航按鈕時顯示確認彈出窗口,如果用戶確定他想要返回上一個屏幕。如何管理ViewWillDisappear中的代碼?

我重寫ViewWillDisappear方法和打電話給我彈出出現,但仍屏幕返回到先前的屏幕,用戶在彈出的確認之前。

彈出窗口顯示和屏幕後面獲取移動到前一個屏幕。

我如何管理它,使屏幕不能移動,直到用戶從彈出確認呢?

回答

0

viewWillDisappear是一個函數,它已經是一個過渡,你不能取消的一部分。 你能做什麼,而不是,是隱藏backBarButton和,而不是它,提供自定義navigationItem.leftBarButton其中也有分配給它的@IBAction。 在@IBAction中,您實現了所需的功能,如呈現彈出窗口。

0

你不能做你想在viewWillDissappear做什麼。相反,你可以指定一個自定義操作後退按鈕這樣的:

func displayConfirmation(sender: AnyObject) { 
    let alert = UIAlertController(title: "", message: "Go back?", preferredStyle: .actionSheet) 
    alert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.default, handler: nil)) 
    alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.default, handler: { action in 
     self.navigationController?.popViewController(animated: true) 
    })) 
    self.present(alert, animated: true, completion: nil) 
} 

self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .Done, target: self, action:#selector(self.displayConfirmation(sender:))) 

選擇實施