我在视图控制器的cellForRowAtindexPath
中手动调用textFieldShouldReturn
,cellForRowAtindexPath
的参数为tableViewOutlet
和indexPath
(“index”in这个例子)。这里cellForRowAtindexPath
和tableViewOutlet
来自另一个视图控制器,我通过实例调用它们。
一旦cellForRowAtindexPath
调用它,就会显示错误:
在展开可选值时意外发现了nil。
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
if(textField == carRating){
let rating = Float(textField.text!)
secondInstanceForMyData.masterCarData[index.row].carRating = rating
let _: MyTableViewCell = myViewControllerInstance.tableView(myViewControllerInstance.tableViewWillLoad as UITableView, cellForRowAt: index) as! MyTableViewCell
}
return true
}
答案 0 :(得分:0)
您在这里调用的是tableview数据源方法 if (is_numeric($_POST['qty_entered'][0]) || is_int($_POST['qty_entered'][0]) || $_POST['qty_entered'][0] > 0) {
print "'<tr><td>' test '</td>'";
,您永远不应该调用它,它必须由您实现。可以这样想,这个方法需要为表视图提供一个单元格,而不是要求它。
如果您想从已填充的tableview中获取单元格,请调用tableview方法tableView(tableView:cellForRowAt:)
cellForRow(at:)
如果您想要更新您的tableview,那么您需要更新数据源并在tableview上调用let indexPath = IndexPath(row: 0, section: 0)
if let cell = tableView?.cellForRow(at: indexPath) as? MyTableViewCell {
// do something with the cell
}
或调用其中一种更新方法。