我正在使用UITableView來顯示使用Interface Builder創建的自定義單元格。表滾動不是很平滑(它「口吃」),這讓我相信細胞沒有被重用。這段代碼有什麼問題嗎?iPhone UITableView與自定義單元結尾。我怎樣才能讓它順利滾動?
- (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;
}
在IB中,單元格的標識符是否設置爲「TwitterCell」? – DyingCactus 2010-03-26 21:35:48