【发布时间】:2017-12-17 19:28:16
【问题描述】:
使用 Swift4、iOS11.1、Xcode9.1,
从 tableView 进行 segue,我试图弄清楚如何检测用户触摸了两个 TextField(在我的自定义单元格中)中的哪一个。我的 custom-Cell tableView 有两个 TextField,如下图所示:
到目前为止,这是我的代码:
// tableView delegation-method:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
self.performSegue(withIdentifier: "goToMyNextVC", sender: cell)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goToMyNextVC" {
let newVC = segue.destination as! MyNextViewController
let indexPath = self.tableView.indexPathForSelectedRow
print(indexPath?.row) // !!!!!! The cell-row is correct
let cell = sender as! MyCustomTableViewCell
newVC.someTextProperty1 = cell.firstTextFiled.text! // works well
newVC.someTextProperty2 = cell.secondTextFiled.text! // works well
// !!!! BUT HOW DO I GET WHICH OF THE TWO TEXTFIELDS WAS TOUCHED ?????????
// newVC.someTextProperty3 = ??????? text of touched TextField ???????
}
}
任何帮助表示赞赏!
【问题讨论】:
标签: ios swift tableview segue custom-cell