gpt4 book ai didi

swift - 快速将数据从 tableviewcontroller 传递到另一个 tableviewcontroller

转载 作者:可可西里 更新时间:2023-11-01 01:58:58 29 4
gpt4 key购买 nike

我有一个正在创建的表单

此表单填充了用户输入的文本字段。回答完所有问题后,会弹出一个按钮进行保存。

我在让此 tableviewcontroller 将数据传递给新的 tableviewcontroller 时遇到问题。我被卡住了,不知道该怎么做。

enter image description here

enter image description here

enter image description here

enter image description here

import UIKit

class TableViewController: UITableViewController, UITextFieldDelegate {

@IBOutlet weak var saveBtn: UIButton!

@IBOutlet var firstNameField: UITextField!
@IBOutlet var middleNameField: UITextField!
@IBOutlet weak var lastNameField: UITextField!
@IBOutlet weak var addressField: UITextField!
@IBOutlet weak var aptNumField: UITextField!
@IBOutlet weak var cityField: UITextField!
@IBOutlet weak var stateField: UITextField!
@IBOutlet weak var zipField: UITextField!
@IBOutlet weak var phoneOneField: UITextField!
@IBOutlet weak var phoneTwoField: UITextField!
@IBOutlet weak var allergiesField: UITextField!
@IBOutlet weak var DobField: UILabel!
@IBOutlet weak var sexField: UILabel!
@IBOutlet weak var hospitalField: UITextField!
@IBOutlet weak var doctorField: UITextField!

override func viewDidLoad() {
super.viewDidLoad()

//Notifications to push datepicker
NotificationCenter.default.addObserver(forName: .saveDateTime, object: nil, queue: OperationQueue.main) { (notification) in
let dateVc = notification.object as! DatePopupViewController
self.DobField.text = dateVc.formattedDate
}

//Notifications to push genderpicker
NotificationCenter.default.addObserver(forName: .saveGender, object: nil, queue: OperationQueue.main) { (notification) in
let genderVc = notification.object as! GenderPopupViewController
self.sexField.text = genderVc.selectedGender
}

updateWidthsForLabels(labels: labels)
}

//Save Button Function
func textFieldDidChange(_ textField: UITextField) {
if textField == firstNameField || textField == lastNameField || textField == middleNameField || textField == addressField || textField == lastNameField || textField == cityField || textField == cityField || textField == stateField || textField == zipField || textField == phoneOneField || textField == phoneTwoField || textField == allergiesField {

saveBtn.isHidden = true
} else {
saveBtn.isHidden = false
}
}

@IBAction func saveBtnPressed(_ sender: Any) {


performSegue(withIdentifier: "saveFirstPageSegue", sender: self)

}

}

最佳答案

开始创建模型怎么样:

表单.swift

struct Form {
var firstname: String?
var middlename: String?
....
var doctor: String?

init(firstname: String, middlename: String, ..., doctor: String) {
self.firstname = firstname
self.middlename = middlename
...
self.doctor = doctor
}

}

现在您可以在保存数据并将数据推送到新 VC 时创建此表单实例:

你的CurrentForm.swift

@IBAction func saveBtnPressed(_ sender: Any) {
let formData = Form(firstname: firstNameField.text, middlename: middleNameField.text, ..., doctor: doctorField.text)
let newVC = myNewViewController()
newVC.form = formData
self.navigationController?.pushViewController(newVC, animated: true)
}

NewViewController.swift

class myNewViewController: UIViewController {

var form: Form?

.....

}

更新:

这是 repo 协议(protocol):https://github.com/FlorianLdt/LFEasyDelegate

有什么问题可以问我

希望对您有所帮助。

关于swift - 快速将数据从 tableviewcontroller 传递到另一个 tableviewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48143437/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com