简体   繁体   中英

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;

您不能这样做,这是tableview的正常行为,但是您应该提高这些函数的性能,例如,如果您从远程源加载图像,请考虑使用延迟加载技术

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM