【发布时间】:2010-06-08 02:37:21
【问题描述】:
我不知道为什么,但我的 UITableView 并不花哨,它在不应该出现的时候显示重复行。
似乎在用户滚动时添加的行(即开始时不在屏幕上的行)正在获取错误行索引的数据。这几乎就像当一个新的单元格出队时,它正在使用一个“已”使用但没有正确清理的单元格。
您是否需要“清理”出队的单元格,以便新单元格不使用已创建的单元格?
我的代码如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
MyDayCell *cell = (MyDayCell *)[tableView
dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyDayCell" owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[MyDayCell class]])
cell = (MyDayCell *)oneObject;
}
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSArray *thisSectionItems = (NSArray*)[self.listData objectForKey: [[NSNumber alloc] initWithInt:section]];
MyDayDetails *rowData = [thisSectionItems objectAtIndex:row];
//setup my cells data here...
return cell;
}
这段代码有什么问题吗?
以前有人见过这样的事情吗?
【问题讨论】:
标签: iphone objective-c uitableview