2011-12-16 57 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不exsist,這是一個3GS的一個致命的組合。 [臉掌]; – Wolfert 2011-12-16 11:53:11

+2

@ maddy2011:你的接受率很差。 – Sarah 2011-12-16 11:59:15

回答

2

[cellIdentifier release] ?? 你不釋放靜態! 您的單元重用可能因爲它而失敗。

也有是在UITableViewCell的分配沒有自動釋放。這應該會導致大量的泄漏,並最終減緩/崩潰應用程序。

這是泄漏+細胞重用失敗

希望這有助於

相關問題