In my app I’m using ELCTextfieldCell. The idea is to use the data entered by the user for some calculations. But there is the problem. I have about 14 cells and, of course, they can’t all fit on a screen. So when I click OK the app is checking if all fiels are filled in:
BOOL complete = YES;
for (int i = 0; i < [cellTextArray count] - [self.numberOfBools intValue]; i++) {
NSIndexPath *iPath = [NSIndexPath indexPathForRow:i inSection:0];
ELCTextfieldCell *theCell = (ELCTextfieldCell *)[self.tableView cellForRowAtIndexPath:iPath];
if (!theCell.rightTextField.text)
complete = NO;
}
This code works perfectly if all the cells are visible, but if some are out, then the complete becomes NO. The output of theCell in gdb is:
(gdb) po theCell
Can't print the description of a NIL object.
Can somebody push me in a right direction please? 🙂
All help will be appreciated, thank you.
EDIT
self.numberOfBools is just an NSNumber with total of bools in these rows. They are using UISwitches, not UITextField as the other cells, so I excluded them from the check.
Complete needs to be calculated on the data that is backing the cells rather than on the cells themselves. Let me explain.
The cell is a visual representation of your data and when it is not in view the run-time will release it and that is why it is nil.
However cellForRowAtIndexPath: creates the cell from data right? (or it is normal to do so) so when the user updates the cell.rightTextField you should update data.rightTextField and then complete should be looking something akin to … and this is pseudocode not compilable
So, in summary cells represent data and they are not guaranteed to persist. You yourself can ensure the data is persisted; therefore test for completeness on the data and not on the cells.