iPhone UITableView stutters with custom cells. How can I get it to scroll smoothly?

Posted by Charles S. on Stack Overflow See other posts from Stack Overflow or by Charles S.
Published on 2010-03-26T21:12:26Z Indexed on 2010/03/26 22:03 UTC
Read the original article Hit count: 415

I'm using a UITableView to display custom cells created with Interface Builder. The table scrolling isn't very smooth (it "stutters") which leaves me to believe cells aren't being reused. Is there something wrong with this code?

- (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;
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uitableview