-1

I'm working on an iPhone app that is a runners pace calculator. I'm using a collection view with a custom cell to display details about different run distances. If I update the run pace text value in a cell, I want the app to recalculate the estimated finish time for the other distances (displayed in the other cells). I'd like a recommendation of the best way to do that. I'm using Swift Version 5.0.1

I'm using UIPickerView to select the hours, minutes and seconds for the run pace. I have a Target/Action for the UITextField Editing Changed event in the cell. That gets invoked. But I'm not sure how I can reload the other cells from the current cell.

I originally hard coded all of the distances on a UIViewController and recalculated the estimated finish time in pickerView didSelectRow. I would prefer to use a list for the different distances hence the collection view.

Peter F.
  • 176
  • 1
  • 11

1 Answers1

1

I assume you have a datasource for your cells, like an array of information or dictionaries that you display in the cells, if you have this then you can perform your calculations and update this datasource, after you have done your calculations that may be on the action invoked in the textfield editing event.

After you have updated the datasource with your new calculations you just have to call collectionView.reloadData() this will update the information in the cells.

Samuel Chavez
  • 768
  • 9
  • 12
  • How would I call `collectionView.reloadData()` from the target in the UICollectionViewCell class. – Peter F. Jul 22 '19 at 20:54
  • The target it's a method declared in your main class right? – Samuel Chavez Jul 22 '19 at 21:32
  • The target is in the custom cell class. It only fires when I type something on the keyboard. When I select a value via the picker view I update the text field using `func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { }` I did create separate sections so that the value gets updated in section 0. When its updated I only need to reload the cells for section 1. – Peter F. Jul 23 '19 at 01:01