iPhone UITableView stutters with custom cells. How can I get it to scroll smoothly?
- by Charles S.
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;
}