![](/img/trans.png)
[英]How to reload data in a TableView from a different ViewController in Swift
[英]Swift - How to reload ViewController from a ModalPopupController
我有2個ViewController,一個名為FirstViewController,它包含一個UIImage和一個UIButton,第二個名為ModalPopupViewController,它包含2個按鈕
所以在我的FirstViewController上,當我按下UIButton時,它將在當前上下文上進行“交叉溶解”過渡
在ModalPopupViewController上,當我按下第一個按鈕時,我選擇了帶有UIImagePickerController的圖片,然后將其保存,當我按下第二個按鈕時,我關閉了視圖,但只有在重新啟動應用程序后,我的圖片才會出現。
離開ModalPopupViewController后,如何重新加載FirstViewController?
我試圖調用viewWillAppear
和viewDidAppear
但是當我從ModalPopupViewController回到FirstViewController時沒有任何追加
您可以使用委托模式
protocol ReloadManager {
func reloadImageV(image:UIImage)
}
當您表示模態時
let modal = ///
modal.delegate = self
present(modal//////
class FirstVC:UIViewController , ReloadManager {
func reloadImageV(image:UIImage) {
// reload here
}
}
class ModalVC:UIViewController {
var delegate:ReloadManager?
@IBAction func btnClicked(_ sender:UIButton) {
delegate?.reloadImageV(image: sendedImage)
dismiss(animated: true, completion: nil)
}
}
//
刪除segue,並在導航到模式的btn動作內部執行此操作,為模式提供情節提要標識符,將其轉換為真實的模式類名稱
let vc = self.storyboard?.instantiateViewController(withIdentifier: "modalID") as! ModViewController
vc.delegate = self
vc.providesPresentationContextTransitionStyle = true;
vc.definesPresentationContext = true;
vc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.present(vc, animated: false, completion: nil)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.