[英]How to get back from modal to main view controller
您可以使用dismiss方法關閉特定的ViewController。
問題是您要如何消除模態顯示的ViewController? 用一個按鈕? 點按視圖中的任意位置? 點擊一個小十字按鈕?
例如,如果您要關閉一個UIButton:
@IBAction func didTapClose(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
}
如果segue是“以模態形式呈現” ,則可以通過此行關閉視圖控制器:
dismiss(animated: true, completion: nil);
否則,如果segue是“ show” ,則可以通過此行關閉視圖控制器:
navigationController?.popViewController(animated: true);
在這種情況下,請確保將ViewController嵌入到情節提要中的navigationController中。 如果您的ViewController未嵌入到navigationController中,並且已使用show segue,則應使用
dismiss(animated: true, completion: nil)
返回上一頁。
還有其他方法可以返回上一頁(例如, segue放松 )
祝好運。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.