UITableViewCell显示索引路径行混乱 [英] UITableViewCell showing indexpath rows out of order

查看:48
本文介绍了UITableViewCell显示索引路径行混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪的问题,我正在创建一个UITableView,设置8行数据.简而言之,我只是返回indexpath行以尝试找出问题所在,但最终,屏幕外的所有行似乎都以奇怪的顺序加载.

Odd question, I am creating a UITableView, setting 8 rows of data. Simply, I'm just returning the indexpath row to try and figure out what is wrong, but ultimately, any rows that are off screen seem to load in a strange order.

例如,第0、1、2、3、4、5行在首次加载时都显示为正常,但随后的6&7个不在屏幕上.滚动到它们时,通常会看到第6行和第0行,或者第6行和第1行.然后,当我向上滚动时,我看到第7行又出现在表格的顶部.

For example, rows 0,1,2,3,4,5 all appear ok on first load, but then 6 & 7 are off screen. When I scroll to them I usually see rows 6 and 0, or 6 and 1. I then see row 7 appear back at the top of the table when I scroll back up.

这是我的代码:

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

我做的事真的很愚蠢吗?干杯

Am I doing something really stupid? Cheers

推荐答案

在if语句中创建单元格,然后在if语句之外设置属性(即标签).

Create your cell in the if statement and then set the properties (ie the label) outside the if statement.

这篇关于UITableViewCell显示索引路径行混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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