У меня есть три viewcontrollers.здесь я хочу добавить значение второго текстового поля viewcontroller к первой табличной метке viewcontroller от третьей кнопки viewcontroller done.Я могу добавить второе текстовое поле viewcontroller к первой метке viewcontroller, используя делегат в то время как popviewcontroller, но я не могу добавить из третьей кнопки viewcontroller.Пожалуйста, помогите мне в коде.
вот мой код:
это мой первый код ВК:
import UIKit
class EmployeeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, EmployeeDelegateProtocol {
var namesArray = [String]()
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
func sendDataToEmployeeViewController(myData: String) {
self.namesArray.append(myData)
tableView.reloadData()
print(namesArray)
print("in delegate method \(namesArray)")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return namesArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! EmployeeTableViewCell
cell.empName.text = namesArray[indexPath.row]
return cell
}
@IBAction func addButtonClicked(_ sender: Any) {
let empProfileVC = self.storyboard!.instantiateViewController(withIdentifier: "EmployeeProfileViewController") as! EmployeeProfileViewController
empProfileVC.delegate = self
self.navigationController?.pushViewController(empProfileVC, animated: true)
}
}
это мой второй код ВК:
при использовании pop он работает
import UIKit
protocol EmployeeDelegateProtocol {
func sendDataToEmployeeViewController(myData: String)
}
class EmployeeProfileViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate,UIImagePickerControllerDelegate {
var delegate: EmployeeDelegateProtocol?
@IBOutlet weak var firstNameTextField: UITextField!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
@objc func saveButtonClicked(){
print("button clicked")
self.delegate?.sendDataToEmployeeViewController(myData: firstNameTextField.text!)
//self.navigationController?.popViewController(animated: true)
}
}
, но я хочу отправить значение с кнопки 3rdVc done:
import UIKit
class EmployeeProfilecreatedPopUpViewController: UIViewController {
var cellProfile: EmployeeProfileViewController?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func doneButtonTapped(_ sender: Any) {
print("done tapped")
let empVC = self.storyboard!.instantiateViewController(withIdentifier: "EmployeeViewController") as! EmployeeViewController self.navigationController?.pushViewController(empVC, animated: true)
}
}
, пожалуйста, предложите мне, как отправить с кнопки третьегоvc done.