我使用一個自定義的XIB檔案作為一個視圖控制器的彈出視窗。該XIB檔案包含兩個按鈕="發送 "和 "添加額外欄位"。選擇添加額外欄位的按鈕會出現另一個嵌入導航控制器中的視圖控制器。當用戶進入該控制器螢屏并選擇他們的額外選項時,這些資料應該被傳回XIB的var extraOptions = [String]()欄位。在那里,用戶應該能夠通過選擇 "發送 "來上傳他們的帖子。
我遇到的問題是資料沒有從嵌入導航控制器中的視圖控制器傳回XIB。
這有可能嗎?我已經嘗試了所有我能想到的解決方案:協議/委托方法,在XIB檔案中設定var extraOptions欄位,從呈現的控制器中,在解散它并回傳到XIB之前,這是我最新的嘗試:
自定義的XIB名為CreatePostModal(view controller thats a pop over)
@objc func addExtraOptions(_ sender: UITapGestureRecognizer? = nil) {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc: UINavigationController = storyboard.instantiateViewController(withIdentifier: "ExtraOptionsNavigationController") as! UINavigationController
vc.委托 = self
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
}
ExtraOptionsViewController
@IBAction func donePressed(_ sender: Any) {
if let navController = presentingViewController as? UINavigationController {
let presenter = navController.topViewController as! CreatePostModal
presenter.extraOptions = self.extraOptionsSelected
print(" These are the options selected ==> (present.extraOptions)") //this prints the options and shows that they're there, but the array is empty whenever a user tries to upload the data.
}
dismiss(animated: true, completion: nil)
}
正如你所看到的,在列印方法中,它列印了變數并顯示資料在那里,但是當回傳XIB檔案,并且用戶保存& 上傳資料時,該欄位顯示為空。
我如何從嵌入導航控制器的視圖中向XIB傳遞資料?
uj5u.com熱心網友回復:
你可以通過三種方式來使用一個:
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/307966.html
標籤:
