我有一个很常见的问题,即使读了一堆类似的帖子后,我不知道如何修复自己,因为使得我的单元格不可重用是而不是选项(该应用程序非常缓慢)。可重复使用的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;
}
不应该有一些方法调用(如设置数字时钟和模拟时钟)在if(worldClockCell == nil)块之外吗? – onnoweb