2011-12-16 12 views
0

以下の方法は、iPhone 3Sでスクロールの問題を引き起こしています。私はスクロールのパフォーマンスを上げることができますが、ネット上でたくさんの検索をしてもそれをどうやって行うのかわからず、いくつかのことを試しました。3GSで実行中のiPhoneアプリのスクロールの問題

セルを不透明にしたり、テーブルビューをサブビューとして作成したりして、下のコードを変更したり、下のコードで変更する必要があるポイントをスクロールすると、スクロールのパフォーマンスが大幅に向上します。 私のコードは以下の通りです。

// cell is created for each row of track. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"tableView cellForRowAtIndexPath"); 


    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    [CellIdentifier release]; 
    cell.accessoryView = nil; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                 reuseIdentifier:CellIdentifier]; 
    } 

    /** saving the data in Book structure.**/ 
    Book *aBook = [appDelegate.books objectAtIndex:indexPath.row]; 

    [cell.textLabel setText: aBook.name]; 

    // indexrow refers to each cell 
    temp =[appDelegate.tracklocation intValue]; 
    requesttemp =[appDelegate.requestlocation intValue];   

    // Coloring Code starts 
    // indexPath starts from 0th cell that is why it is incremented by 1 
    if(temp==(indexPath.row+1)) 
    { 
     NSLog(@"value of temp inside if is = %d",temp); 
     NSLog(@"value of indexrow inside if is=%d",(indexPath.row+1)); 
     UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"speaker.png"]]; 
     imageView1.backgroundColor = [ UIColor greenColor ]; 
     cell.contentView.backgroundColor = [ UIColor greenColor ]; 
     [cell.textLabel setBackgroundColor:[UIColor greenColor]]; 
     [cell.textLabel setTextColor:[UIColor blackColor]]; 
     [cell.detailTextLabel setBackgroundColor:[UIColor greenColor] ]; 
     [cell.detailTextLabel setTextColor:[UIColor blackColor] ]; 
     cell.accessoryView = imageView1; 
     [imageView1 release]; 
    } 
    else 
    { 
     cell.contentView.backgroundColor = [ UIColor whiteColor ]; 
     [cell.textLabel setBackgroundColor:[UIColor whiteColor] ]; 
     [cell.textLabel setTextColor:[UIColor blackColor ]]; 
     [cell.detailTextLabel setBackgroundColor:[UIColor whiteColor]]; 
     [cell.detailTextLabel setTextColor:[UIColor grayColor] ]; 
    } 

     while(requesttemp>temp) 
     { 
      if (requesttemp==(indexPath.row+1)) 
      { 
       if (colorflag==1) 
       { 
        NSLog(@"value of request temp inside while is = %d",requesttemp); 
        NSLog(@"value of indexrow inside while is=%d",(indexPath.row+1)); 
        cell.contentView.backgroundColor = [ UIColor blueColor ]; 
        [cell.textLabel setBackgroundColor:[UIColor blueColor ]]; 
        [cell.textLabel setTextColor:[UIColor whiteColor ]]; 
        [cell.detailTextLabel setBackgroundColor:[UIColor blueColor] ]; 
        [cell.detailTextLabel setTextColor:[UIColor whiteColor] ]; 
       } 
      } 
      requesttemp=requesttemp-1; 
     } 
    }  

    cell.detailTextLabel.text = abook.artist; 

    cell.detailTextLabel.numberOfLines = 1; 

    cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap; 
    NSLog(@"RootViewController cellForRowAtIndexPath %@ ",cell); 

    return cell; 
} 
+1

iPhone 3Sが、それは3GSだ、exsistていないのに役立ちますリーク+セルリユース障害の致命的な組み合わせ

希望です。 [手のひら]。 – Wolfert

+2

@ maddy2011:あなたの受け入れ率は非常に悪いです。 – Sarah

答えて

2

[cellIdentifier release] ?? 統計情報を公開していません! あなたのセルの再利用はおそらく失敗しているでしょう。

また、UITableViewCell割り当てには自動解放がありません。これは、多くのリークを引き起こし、最終的にはアプリケーションの速度を落としたりクラッシュさせたりするはずです。

これは、これは

+0

訂正していただきありがとうございます。私はそれに応じてコードを変更し、私は私のデバイスを戻すと、このケースをテストします。 もう1つのことは、私が使用している '* abook'オブジェクト' Book * aBook = [appDelegate.books objectAtIndex:indexPath.row]; ' は**構造体*として宣言されています。 *。これにより、レコードを取得するのが遅くなり、配列を使用するのではなく、セルに割り当てることができますか? – maddy2012

+1

それは問題ではありません。どこかで "値渡し"をしない限り、Cを混ぜてもパフォーマンス上の問題はありません。 このコード行は大丈夫です。 – NSIntegerMax

+0

私は上記のコードで2行を変更し、多くのスクロールを改善しました – maddy2012

関連する問題