Sea*_*404 1 uitableview ios swift
我在视图控制器中有一个tableView,我在那里显示来自API调用的数据,现在如果用户选择了一个tableview单元格(比如TableView中的第2行),我想获取那些数据(TableView第2行中的数据)并显示它在同一屏幕上的文本字段中.做这个的最好方式是什么?
最简单的方法是可以显示在显示UIAlertController与textField上didSelecttableViewCell的.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alert = UIAlertController(title: "Edit Data", message: "Edit corresponding detail", preferredStyle: .alert)
alert.addTextField { (textField) in
textField.placeholder = "Enter name"
textField.text = yourArray[indexPath.row]
}
alert.addAction(UIAlertAction(title: "Edit", style: .default, handler: { (action) in
//Edit data on array
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
892 次 |
| 最近记录: |