滚动UITableView时显示不正确的单元格数据

use*_*236 1 cocoa-touch objective-c uitableview ios

我面临一些奇怪的问题.每当我滚动表格视图时,我的数据都会被其他单元格替换.每次都会被不同的细胞数据所取代.我没有看到这个替代品的任何特定模式.

Eri*_*k B 7

以下是如何正确重用单元格的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {        
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    cell.textLabel.text =  [array objectAtIndex:indexPath.row];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

如果您提供代码,我们可以修改它而不是为您提供通用示例.


Ram*_*ams 7

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
Run Code Online (Sandbox Code Playgroud)