奇怪的問題,我創建一個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