使UITableView中的可重用单元出队 [英] Dequeuing reusable cells from UITableView

查看:57
本文介绍了使UITableView中的可重用单元出队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么此代码可以正常工作:

Why this code works fine:

- (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.text = [NSString stringWithFormat:@"cell%i%i", indexPath.section, indexPath.row];
    }    
    return cell;
}

据我了解,单元格标识符仅当我将 cell.textLabel.text = ... 行移出if语句时,此代码才能正常工作.换句话说,为什么标签具有正确的文本?

As far as I understood cell identifiers, this code should work correctly only if I move cell.textLabel.text = ... line out of if-statement. In other words, why labels have correct texts???

推荐答案

尝试创建比您在屏幕上看到的更多的单元格,一旦它们出队,它们将不再具有您期望的文本...

Try creating more cells than you can see on your screen and as soon as they get dequeued they will no longer have the text you expect...

对于您在屏幕上看到的大约5行,基本上可以,但是一旦开始滚动,您就会看到一些有趣的"东西:)

It will basically be okay for 5 or so rows you see on the screen but as soon as you start scrolling you'll be seeing some "interesting" stuff :)

这篇关于使UITableView中的可重用单元出队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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