DequeueReusableCellWithIdentifier not working

I want to load about 6,000 - 8,000 lines in a UITableview. I get data from the server using an asynchronous call, and when I get the data that I call

  [tableView reloadData]

This is a table update. But for some reason, my application is stuck and freezes. When I debug it, I found that the cellforrowatindexpath is called 6,000 times (in the main thread) and dequeueReusableCellWithIdentifier always returns null.

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath{ CDTableRowCell *cell = nil; // Create and Resue Custom ViewCell static NSString *CellIdentifier = @"CellIdentifier"; cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // got into render/theme objec if(cell == nil){ cell = [[CDTableRowCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } // MODIFYING CELL PROPERTIES HERE FROM AN ARRAY // NO HTTP CALLS } 

Also, tableview starts reusing a cell when I start scrolling, but before that I never create a new one. Any clue why this is weird behavior ???

+4
source share
2 answers

try it,

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier =@ "Cell"; UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } return cell; } 
0
source

The method in your question is not a method for tabulating data. The datasource method has a table view as an argument. You wrote a method that you can use to get a cell from the tableView itself, and not to get a new cell from the data source.

I don’t know how often this method is called, but redefining it is almost certainly not what you want to do.

I assume you subclassed uitableview as your own data source? If so, you need to have the code in your question in the datasource tableView:cellForRowAtIndexPath: method and not override the method as you have now.

0
source

All Articles