Reputation: 16124
I have a tableview with two textfields in each cell. My intended behavior is that the user can either drag the tableview to end editing or press Return to advance to the next cell/textfield. I have been trying to use the textFieldShouldReturn
and textfieldDidEndEditing
methods, however, I am unable to determine in the EndEditing
method what the cause of end editing was.
Should I be using some other method to determine that a textfield
will end editing due to a drag?
Upvotes: 1
Views: 44
Reputation: 25280
First, you need a trigger when the table view is dragged. User this method from UITableViewDelegate
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
yourTextField.resignFirstResponder()
}
Now, you need to find your text field in this delegate method. I will just give you a hint on this. Since each cell has the textfield, in your cellForRow
method, simply set your textfield's tag to be indexPath.row
. Then in this delegate method, you can find our your cell and textfield by index number.
Upvotes: 1