我正在使用 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;
}