views:

173

answers:

3

I have a Table View Controller with cells. I want to update the text that is displayed on the visible UITableViewCells. Is there a way to get a reference to the cells that are currently on the screen?

+1  A: 

What you can do is go and ask for the cells at index Paths using - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath, if they are not nil, you know they are on the screen and you can do what you wish with them. Also if you know the visible rectangle on the screen (which shouldnt be hard to get) you can use tableViews - (NSArray *)indexPathsForRowsInRect:(CGRect)rect and you can get all your visible i ndex paths and use cellForRow in order to get the cells back.

As long as this is marked as answer, i stand corrected, like others said you can do [tableView visibleCells]

Daniel
A: 

Call the reloadData method of the UITableView. It will force the table view to update all the visible cells information (check the documentation for more information).

TehJabbit
+6  A: 

You can query the visible cells;

[myTableOutlet visibleCells];

Where myTableOutlet refers to your UITableView, and visibleCells returns an array of table cells. You could also use indexPathsForVisibleRows, which will return an array of index paths for the rows that are currently visible.

If you put the code in a ,notification triggered, function, you could update only the currently visible cells.

MiRAGe