0
我有一個很多行的UITableView。每行都有一個UIView,我在cellForRowAtIndexPath中編輯。我的問題是,這在iPod touch上非常落後。我不確定爲什麼會出現這種情況,因爲iPod應該能夠同時在屏幕上顯示超過11個UIViews?有誰知道爲什麼會發生這種情況?使用單元格子視圖的UITableView中的滾動性能不佳。
編輯 - 這裏是代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIView *colorView = (UIView *)[cell viewWithTag:1];
UILabel *label = (UILabel *)[cell viewWithTag:2];
colorView.layer.cornerRadius = 10;
colorView.layer.borderColor = [UIColor blackColor].CGColor;
colorView.layer.borderWidth = 2.0f;
colorView.layer.masksToBounds = YES;
switch (indexPath.row) {
case 0:
label.text = @"White";
colorView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
break;
case 1:
label.text = @"Olive";
colorView.backgroundColor = [UIColor colorWithRed:0.814 green:0.551 blue:0.119 alpha:1];
break;
case 2:
label.text = @"Dark Blue";
colorView.backgroundColor = [UIColor colorWithRed:0.036 green:0 blue:1 alpha:1];
break;
case 3:
label.text = @"Dark Green";
colorView.backgroundColor = [UIColor colorWithRed:0 green:0.387 blue:0.006 alpha:1];
break;
case 4:
label.text = @"Orange";
colorView.backgroundColor = [UIColor colorWithRed:1 green:0.500 blue:0 alpha:1];
break;
case 5:
label.text = @"Dark Brown";
colorView.backgroundColor = [UIColor colorWithRed:0.399 green:0.269 blue:0.137 alpha:1];
break;
case 6:
label.text = @"Dark Red";
colorView.backgroundColor = [UIColor colorWithRed:0.530 green:0.017 blue:0 alpha:1];
break;
case 7:
label.text = @"Maroon";
colorView.backgroundColor = [UIColor colorWithRed:0.502 green:0 blue:0.251 alpha:1];
break;
case 8:
label.text = @"Yellow";
colorView.backgroundColor = [UIColor colorWithRed:0.865 green:0.864 blue:0.002 alpha:1];
break;
case 9:
label.text = @"Purple";
colorView.backgroundColor = [UIColor colorWithRed:0.460 green:0 blue:0.865 alpha:1];
break;
default:
label.text = @"";
colorView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
break;
}
return cell;
}
感謝
爲什麼在每個出列單元格上設置colorView的圖層屬性(cornerRadius等)?如果單元出隊,應該已經設置。 – joern
@joern可能是因爲在故事板中,您總是從出列單元中獲取單元格,表格會自動從原型中爲您加載。因此無法判斷您是否擁有「新」單元或重用單元。 – jrturton
啊,好的。這就說得通了。 – joern