滚动UITableView时单元格数据显示不正确 [英] Incorrect cell data display when scrolling UITableView

查看:75
本文介绍了滚动UITableView时单元格数据显示不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一些奇怪的问题。每当我滚动表格视图时,我的数据就会被其他单元格替换。每次,它都会替换为不同的单元格数据。我没有看到此替换中的任何特定模式。

I am facing some weird problems. Whenever I scroll my table view, my data gets replaced with other cells. Each time, it gets replaced with different cell data. I am not seeing any particular pattern in this replacement.

推荐答案

下面是有关如何正确重用单元格的代码:

Here's code for how to properly reuse a cell:

- (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;
}

如果您提供代码,我们可以对其进行修改,而不是给出通用示例。

If you provide your code we could modify that instead of giving you generic examples.

这篇关于滚动UITableView时单元格数据显示不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆