Do not extract the code from the if (cell == nil) block if (cell == nil) . Instead, create a representative identifier for the cell you are creating; try and make sure that all the contents of the cell are indicated in the identifier. For example, if you have 3 numbers, make sure that these three numbers in the identifier in a unique way apply only to a cell with such content.
Let's say you have three NSArray properties in your class: array1, array2, and array3, which have int values ββwrapped inside NSNumber objects. You want to use these NSArrays to populate a UITableView, this is what I would do:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *identifier = [NSString stringWithFormat:@"%@-%@-%@", [[array1 objectAtIndex:indexPath.row] intValue], [[array2 objectAtIndex:indexPath.row] intValue], [[array3 objectAtIndex:indexPath.row] intValue]]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
source share