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