I have the structure of my TableViewController
as such (mentioning for delegation purposes):
----View
-----Scroll View
------Content View
-------TableView
--------TableViewCell
I can get all of the rows and sections of my TableView
to load correctly. Each TableViewCell
has a UITextField
which is editable. When the user begins to edit the UITextField
, I need to be able to retrieve the contents of what the user types. To update the correct data sets, the way I am currently doing it is retrieving the indexPath
of the UITextField
My issue is this: When I scroll slowly and click on the UITextField
one by one, I do not crash. However, if I click on a cell and scroll down quickly (even if I stay in the same section
), I crash due to the indexPath
being null.
In my delegate I have this:
func textFieldDidEndEditing(_ textField: UITextField) {
//here is the code I am using to determine the indexPath
let view = textField.superview!
let cell = view.superview as! UITableViewCell
let viewController = ShowPointsViewController() //this is the name of my ViewController
let textFieldIndexPath = PointSourcesTV.indexPath(for: cell) //this is the name of my TableView
print(textFieldIndexPath) //Returns nil here if I scroll too quickly
let key = tableHeaders[(textFieldIndexPath?.section)!]
}