IOS SDK: How to get a cell in the form of a table that is not visible?

How to get a cell for indexPath that is currently not visible in the table? (cell out of range)

Code to get my cell:

NSString *name = [[(ELCTextfieldCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] rightTextField] text]; 

-cellForRowAtIndexPath... returns nil because the cell at the required indexPath is out of range. So, how do I get the correct cell, not null?

+8
ios iphone uitableview
source share
5 answers

This is not how it works. You need to capture and save information as soon as it is entered or modified. It can easily go out of scope, and you cannot guarantee that the life of your cell is long enough. Well, technically you can hold it (and always return the same cell for the same index path), but I would question this design.

+4
source share

UITableView only supports visible cells. If you need one that doesn't display, you should call tableView:cellForRowAtIndexPath: UITableView dataSource . So, if self is a class that is dataSource :

 UITableViewCell * cell = [self tableView:table cellForRowAtIndexPath:indexPath]; 
+15
source share

UITableViewCells are used for reuse / reuse in such a way that users do not need to create more cells than the number of visible ones. Usually you do not need access to a cell that is not displayed. It is enough to get access to the data source and get / set the corresponding data there. Cells are designed to display some state of the data source. Not the data source itself :)

Edit:

You said that you need information (text) from one cell above, right? If you use the cellForRowAtIndexPath: method, the cell will be recreated, but you may not get the text that was in the text box. Cause? because you probably haven’t saved it elsewhere. If you saved it, then get access to it directly, and not through the cell.

+2
source share

Is the information to populate a table coming from an array? Could you get this straight from the array with index 0, just as your cellForRowAtIndexPath will apparently retrieve and populate this cell when it is displayed?

0
source share

In response to @Raphael's answer: Here is a (working) quick 3 solution:

UITableViewCell cell = self.tableView(self.tableView, cellForRowAt: indexPath)

0
source share

All Articles