嗨我在這裏的建議,看看我在做什麼是最好的選擇是很好的迅速。我有從viewcontroller1呈現的視圖控制器。在viewcontroller2我有一個文本框,當文本已滿時,將文本保存到我的單例文件,並通過協議在視圖控制器1中啓動一個操作,以將該文本保存到數據庫並使用這些標籤更新視圖控制器1中的uilabels,然後我解僱了視圖控制器二。我從視圖控制器1中的視圖控制器2啓動一個功能,將單個數據保存到數據庫。這很好嗎。如果你有任何問題隨時問。從另一個視圖控制器的視圖控制器觸發器操作
class ViewController1: UIViewController, EditProtocol{
var label = UIlabel()
@IBAction func Editname(_ sender: Any) {
if let vc = storyboard.instantiateViewController(withIdentifier: "ViewController2Identifier") as? ViewController2{
vc.controller = self
vc.modalPresentationStyle = .custom
vc.modalTransitionStyle = .crossDissolve
vc.setViewControllers([ProductInformation], animated: true)
self.present(vc, animated:true, completion: nil)
}
}
func SaveName() {
label.text = singleton.shared.text
}
protocol EditProtocol {
func SaveName()
}
class ViewController2: UIViewController{
var controller: EditProtocol?
@IBOutlet weak var Name: UITextField!
@IBAction func Back(_ sender: AnyObject) {
singleton.shared.text = Name.text
controller?. SaveName()
self.dismiss(animated: true, completion: nil)
}
}
https://stackoverflow.com/a/30541063/2303865 –