Answer the question
In order to leave comments, you need to log in
How to update data in ViewController after dismiss() in popup?
Friends, good day. Quite new to Swift. I apologize in advance if this is a dumb question.
There is a method that receives a list of counterparties via API:
class SupplierViewController: UIViewController {
@IBOutlet weak var suppliersTableView: UITableView!
var suppliers: [Supplier] = []
func fetchSupplierList() {
SupplierService.fetch(url: "http://localhost:8000/finance/api/suppliers/") { result in
switch result {
case .success(let suppliers):
self.suppliers = suppliers
self.suppliersTableView.reloadData()
case .failure(let error):
print("Failed to fetch suppliers", error)
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
suppliersTableView.delegate = self
suppliersTableView.dataSource = self
fetchSupplierList()
}
@IBAction func addButtonPressed(_ sender: UIButton) {
performSegue(withIdentifier: "addSupplierSegue", sender: self)
}
}
class AddSupplierViewController: UIViewController {
@IBOutlet weak var name: UITextField!
@IBOutlet weak var shortName: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func addSupplierPressed(_ sender: UIButton) {
guard let name = name.text else { return }
guard let shortName = shortName.text else { return }
SupplierService.createSupplier(url: "http://localhost:8000/finance/api/suppliers/", name: name, short_name: shortName, inn: "123456") { error in
if let error = error {
print("Failed to create", error)
return
}
DispatchQueue.main.async {
self.dismiss(animated: true, completion: nil)
}
}
}
}
Answer the question
In order to leave comments, you need to log in
True to use delegates .
You can try hacking through parent and type casting. I do not recommend.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question