Get UITableViewCell from UITableView using cellForRowAtIndexPath

I am trying to get subclasses of a UITableViewCell (a class called "MasterCell") from my UITableViewController with a changing index. Say I get a cell in the first row:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0]; MasterCell *cell = (MasterCell *)[self.tableView cellForRowAtIndexPath:indexPath]; 

This happens in my viewWillAppear method. Unfortunately, the cell is zero when debugging.

I have different cells / rows where I need to change some values ​​in the viewWillAppear method. Do you have any hints of me?

+4
source share
1 answer

[self.tableView cellForRowAtIndexPath:indexPath] returns nil for cells that are not currently visible.

You should not use cells to store model data, because cells are reused when scrolling up or down.

+11
source

All Articles