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;
}
Couple things:
cellForRowAtIndexPath
methodYou'll probably find a lot of speedup by not loading nibs and creating your custom cells completely in code instead.
Otherwise you'll need to do some profiling to figure out where any hidden slowdowns are lurking.
If you are using a nib file to load the table view cell then obviously it will take time to load and will give a jerky feeling.
So the best way to do so is to design the view using codes and override the method
drawInRect
This will give your application a very smooth scroll in case of UITableView.
Maybe this blog entry from atebits (creators of Tweetie) can help you: http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/