I need to loop through tableview cells in different sections to calculate something in each one; however when I try to do this:
CustomCell * c = (CustomCell *)[self.table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:i]
if the section “i” is not visible I can’t get the content inside.
I must say that the content I want to calculate in each cell will vary before I call the calculate method, so I can’t populate the tableview then calculate.
Any ideas?
You should not be performing calculations based on the content of
UITableViewCellobjects, because they fundamentally belong to the presentation layer; there should be no calculations going on in the presentation layer, only hiding and displaying things.For calculations, you should go directly to the layer from which your
UITableViewDataSourcegets its data (presumably, that would be your model classes) and do the calculations there. Better yet, move the calculation to the model layer, and put out a method for getting it on demand.If you are modifying the existing code written by someone else, start by examining the
tableView:cellForRowAtIndexPath:method in theUITableViewDataSourceto see from where it gets its data. Presumably, that place has all the data available, regardless of whether it is showing on the screen or not.