Oktay
Oktay

Reputation: 531

UITableView scrolling

I fill a table view with 10 rows. When I scroll up the table the first 2 or 3 lines are frozen for a while. I only see the last rows for 2 or 3 seconds. I realize that scrolling the table calls cellForRowAtIndexPath and willDisplayCell functions. I use those functions. It seems the calls for these functions decreasing the response time. How can I disable calling these functions when scrolling the table? Note that I dont want to disable scrolling.

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [[self.items objectAtIndex:indexPath.row] valueForKey:@"name"]; 

if ([indexPath row] % 2) 
    cell.backgroundColor = [UIColor whiteColor];
else 
    cell.backgroundColor = [UIColor colorWithRed:0/255.0 green:46/255.0 blue:59/255.0 alpha:0.1];

return cell;

Upvotes: 0

Views: 264

Answers (2)

Aaron Brager
Aaron Brager

Reputation: 66242

You can't stop calling these methods. If you post the code for them we can help you optimize them.

Number 1 cause of slowness in UITableViews is not reusing your cells. Are you reusing your cells?

Upvotes: 1

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

You cannot do that, that is the normal behavior of the tableview, however you should increase the performance of these functions, for example if you do load images from a remote source consider using lazy loading technique

Upvotes: 1

Related Questions