2011-10-12 97 views
0

我有一個很常見的問題,即使讀了一堆類似的帖子後,我不知道如何修復自己,因爲使得我的單元格不可重用是而不是選項(該應用程序非常緩慢)。可重複使用的UITableViewCells重複內容

的問題

當我有6首或更多個小區(最大16)中,第一5個細胞的內容物開始出現在所有其它小區的時候我滾動到它們。

儘管我正在使用可重用的單元格,但爲什麼我的單元格內容沒有被存儲在我的NSMutableArrays中的新數據刷新?

守則

- (UITableViewCell *)tableView:(UITableView *)tableView 
cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    WorldClockTableViewCell *worldClockCell = (WorldClockTableViewCell*)[tableView dequeueReusableCellWithIdentifier:kCellID]; 
if(worldClockCell == nil) { 

    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"WorldClockTableViewCell" owner:self options:nil]; 
    worldClockCell = [topLevelObjects objectAtIndex:0]; 

    /* 
    Set Scrolling to OFF by default. 
    User can scroll when table is in edit mode. 
    */ 
    [worldClockCell.scrollView setScrollEnabled:NO]; 

    // Set Digital Clock in timeLabel 
    [self setDigitalClockInLabel:worldClockCell inRow:indexPath.row]; 

    // Set Analog Clock Carousel in ScrollView in every cell. 
    [self setAnalogClocksInScrollView:worldClockCell inRow:indexPath.row]; 

    // Scroll to User's Preferred Clock (if this is the first launch of WorldClockTableViewController) 
    if([[shouldAutoScrollArray objectAtIndex:indexPath.row] boolValue] == YES) { 

     [self scrollToUsersPreferredClock:worldClockCell atRow:indexPath.row]; 
     [shouldAutoScrollArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithBool:NO]]; 

    } 

    // Add City Name to cityLabel in every cell 
    [worldClockCell buildFormattedCityName:[model.timeZoneCityNames objectAtIndex:indexPath.row]]; 

    // Make sure new clocks created while in 'edit' mode don't scroll out of the cell 
    worldClockCell.scrollView.frame = worldClockCell.scrollViewFrame; 


} 

return worldClockCell; 
} 
+0

不應該有一些方法調用(如設置數字時鐘和模擬時鐘)在if(worldClockCell == nil)塊之外嗎? – onnoweb

回答

2

你這樣做,只有當它創造了一個新的小區所有單元格配置,而不是是否出隊之一。拉東西展現出來的

if(worldClockCell == nil) 

除了

NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"WorldClockTableViewCell" owner:self options:nil]; 
worldClockCell = [topLevelObjects objectAtIndex:0]; 

,除非你真的只需要做一次,當細胞被創建(它的重新配置,以顯示新的數據,而不是每次)。

+0

對,之前我做過,它會讓應用程序非常慢。我猜這個問題與我在單元格中的視圖數量有關,對嗎? – ArtSabintsev

+0

你的單元有多少個視圖?通常不是太多問題。也許你可以發佈你的方法實現,看看你是否在做一些非常昂貴的事情。也考慮使用UINib。 – jbat100

+0

我有兩個標籤,一個帶6頁的分頁滾動視圖,以及兩個小圖片視圖。代碼全部從一個自定義的類中拖到這個tableviewcontroller中。我會看看UINib。 – ArtSabintsev

1

您應該將所有的數字和模擬時鐘移出檢查出列可重用單元的範圍,並且所有的都是好的。您的內容正在重複播放,因爲曾經滾動出視圖的單元格將保留以供重用。