2012-10-09 36 views
1

我有以下cellForRowAtIndexPath方法的代碼:的UITableViewController滾動滯後與大量圖像

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"champion cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    UIImage *cellIcon = [UIImage imageNamed:[arrayOfChampionPictures objectAtIndex:indexPath.row]]; 
    [[cell imageView] setImage:cellIcon]; 

    cell.imageView.frame = CGRectMake(0.0f, 0.0f, 70.0f, 70.0f); 

    cell.imageView.layer.cornerRadius = 7; 
    [cell.imageView.layer setMasksToBounds:YES]; 

    cell.textLabel.text = [arrayOfChampionNames objectAtIndex:indexPath.row]; 

    return cell; 
} 

arrayOfChampionNames存儲在NSMutableArray包含圖片名稱本地數據庫。這是關於我的UITableView中的圖像103單元格。它在第一次滾動時從頭到尾滯後,然後順利滾動。模擬器上沒有滯後。


可能的解決方案,我想出了,但我不知道如何實現它們滾動後

  • 加載圖像,
  • 預加載圖像數據到UITableView的。
+0

您需要重用您的單元格並將圖像大小調整爲單元格圖像視圖的大小 - 這可能是您遇到滯後現象的原因。 – sooper

+0

@sooper謝謝你的迴應,我會嘗試! – ignotusverum

回答

0

你忘了的東西:

static NSString *CellIdentifier = @"champion cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

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

這樣你實際上會利用您所創建的可重複使用的標識符。

+0

感謝您的迴應,但它仍然laggy – ignotusverum

+0

,我忘了提及,在模擬器上沒有滯後 – ignotusverum

+0

@anonymous有道理,永遠不要相信模擬器與這種事情。你的電腦有更多的RAM,然後你打電話。你使用的圖像有多大? –

2

我會告訴你滯後來自哪裏 - 拐角半徑。預先計算圓角的圖像。動態地執行它們會導致滾動性能下降。

+0

您先生是天才! –