Вот мой соответствующий код:
ViewController "B" (тот, который передает данные обратно в предыдущий контроллер представления):
Код: Выделить всё
protocol CountryFieldProtocol {
func setField(countryName: String)
}
class TableViewController: UITableViewController {
var countryProtocol: CountryFieldProtocol?
...
func dismiss() {
for item in countries {
if item.isSelected == true {
print("what is the country selected?" + item.name)
countryProtocol?.setField(item.name)
}
}
self.navigationController?.popViewControllerAnimated(true)
}
Код: Выделить всё
func setField(countryName: String) {
textField.text = countryName
print("the country selected is:" + textField.text!)
}
@IBAction func textFieldEditing(sender: AnyObject) {
textField.resignFirstResponder()
let tableViewController = self.storyboard?.instantiateViewControllerWithIdentifier("CountryList") as? TableViewController
tableViewController?.countryProtocol = self
self.navigationController?.pushViewController(tableViewController!, animated: true)
}
Теоретически предполагается, что выбор пользователя из списка должен появиться в текстовом поле в первом контроллере представления. К сожалению, хотя выбор выводится на консоль с помощью функции setField в первом контроллере представления, строка не отображается в textField. Что я делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/379 ... r-in-swift
Мобильная версия