iPhone UITableView与自定义单元格断断续续.如何让它顺利滚动?

use*_*435 2 iphone interface builder uitableview

我正在使用UITableView来显示使用Interface Builder创建的自定义单元格.表格滚动不是很平滑(它"断断续续")让我相信细胞没有被重复使用.这段代码有问题吗?

- (UITableViewCell *)tableView:(UITableView *)tableView 
       cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"TwitterCell";
TwitterCell *cell = (TwitterCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil){
    //new cell
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TwitterCell" 
                                                   owner:nil options:nil];

    for(id currentObject in topLevelObjects)
    {
        if([currentObject isKindOfClass:[TwitterCell class]])
        {
            cell = (TwitterCell *)currentObject;
            break;
        }
    }

}

if([self.tweets count] > 0) {
    cell.lblUser.text = [[self.tweets objectAtIndex:[indexPath row]] username];
    cell.lblTime.text = [[self.tweets objectAtIndex:[indexPath row]] time];
    [cell.txtText setText:[[self.tweets objectAtIndex:[indexPath row]] text]];
    [[cell imgImage] setImage:[[self.tweets objectAtIndex:[indexPath row]] image]];
} else {
    cell.txtText.text = @"Loading...";
}


cell.selectionStyle = UITableViewCellSelectionStyleNone;

return cell;
}
Run Code Online (Sandbox Code Playgroud)

FRo*_*owe 6

也许来自atebits(Tweetie的创建者)的博客文章可以帮助您:http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/

切入追逐,这是秘密:每个表格单元一个自定义视图,并自己绘制.听起来很简单?那是因为它是.它实际上比处理标签和图像的大量子视图更简单,并且它的速度提高了大约数十亿倍(根据我的非正式测试).