0

多くの行を持つUITableViewがあります。各行には、cellForRowAtIndexPathで編集するUIViewが含まれています。私の問題は、これがiPodtouchでひどく遅れることです。iPodは画面上で一度に11を超えるUIViewを取得できるはずなので、なぜこれが起こっているのかわかりませんか?なぜこれが起こっているのか誰かが知っていますか?

編集-ここにコードがあります:

- (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;
}

ありがとう

4

1 に答える 1

2

ここでできることがいくつかあります。

Quartz デバッグをオンにします (デバイス上で計測器を使用するか、ごく最近ではシミュレーターで)。色が混ざったレイヤー - ほとんどが緑色に見えるはずです。そうでない場合は、新しいビューが不透明としてマークされていることを確認してください。透明なビューをスクロールすると、多くのパフォーマンスが必要になります。

それでも問題が解決しない場合は、計測器で時間プロファイラーを使用してプロファイリングします。費やされた時間はどこにありますか?たとえば、背景に使用している色をキャッシュする必要がありますか?

レイヤー プロパティは、理想的には 1 回だけ設定する必要があります。カスタム セル サブクラスの awakeFromNib は、これを行うのに適した場所です。

于 2012-06-10T08:11:49.860 に答える