NSFetchedResultsController error: ‘no object at index in section at index 0’

I am not certain if this will work but it seems too long for it to be a comment so give the below a try.

Initially I told you could use tag to identify a specific view which is good for quick and simple implementations but when rows get moved / deleted as we have it now, it will be very difficult to manage using tags as you have to constantly update them.

For static table views, they are fine but if your rows will change, then more sophisticated patterns like delegate / observer might be better.

Anyways, what I think can help your situation for now in textFieldDidBeginEditing is stop using the tag to get the index path and get the indexpath from what is tapped.

I still think maybe delegate pattern is better but this might work for you:

func textFieldDidBeginEditing(_ textField: UITextField) {
    // Get the coordinates of where we tapped in the table
    let tapLocation = textField.convert(textField.bounds.origin,
                                        to: tableView)
    
    if let indexPath = self.tableView.indexPathForRow(at: tapLocation)
    {
        // don't use tag of textfield anymore
        pickedCurrency
            = fetchedResultsController.object(at: IndexPath(row: indexPath,
                                                            section: 0))
        
        numberFromTextField = 0
        textField.textColor = UIColor(named: "BlueColor")
        textField.placeholder = "0"
        textField.text = ""
    }
}

Does this help ?

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top