奇怪的问题,我创建一个UITableView,设置8行数据。简而言之,我只是返回indexpath行来尝试找出错误,但最终,任何屏幕外的行似乎都以奇怪的顺序加载。UITableViewCell显示索引路径行乱序
例如,行0,1,2,3,4,5在第一次加载时都显示为正常,但随后屏幕上出现6 & 7。当我滚动到他们时,我通常会看到行6和0,或6和1.然后,当我向后滚动时,我会看到行7出现在表格的顶部。
这里是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[cell.textLabel setText:[NSString stringWithFormat:@"Row: %d", [indexPath row]]];
}
return cell;
}
我是不是很笨?干杯
这很奇怪,因为如果你没有一个单元格,它应该创建单元格。现在如果一个单元格存在,它应该重用它,但文本可能是旧值,所以你应该重置标签 – Rudiger 2010-08-28 21:55:43
如果你创建一个空白的导航iPhone应用程序与Xcode它给你上面的代码(没有标签部分) – mootymoots 2010-08-28 21:56:32
只该标签应该设置在if语句之外。该模板对于创建单元格是正确的。 – Rudiger 2010-08-28 22:00:27