2011-10-12 73 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

您应该将所有的数字和模拟时钟移出检查出列可重用单元的范围,并且所有的都是好的。您的内容正在重复播放,因为曾经滚动出视图的单元格将保留以供重用。