Get indexPath of UITextField in UITableViewCell with Swift

前端 未结 4 1218
庸人自扰
庸人自扰 2021-02-04 08:26

So, I\'m building a Detail View Controller App that presents a Table with a two-part cell: the label and the Text Field.

I\'m trying to retrieve the Text Field value and

4条回答
  •  天涯浪人
    2021-02-04 09:04

    You'll want to cast the first and second lines in your function, like this:

    func textFieldDidEndEditing(textField: UITextField!){
        var cell: UITableViewCell = textField.superview.superview as UITableViewCell
        var table: UITableView = cell.superview as UITableView
        let textFieldIndexPath = table.indexPathForCell(cell)
    }
    

    superview returns a UIView, so you need to cast it to the type of view you expect.

提交回复
热议问题