Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从UITableView中退出可重用单元队列_Iphone_Objective C_Uitableview_Deque - Fatal编程技术网

Iphone 从UITableView中退出可重用单元队列

Iphone 从UITableView中退出可重用单元队列,iphone,objective-c,uitableview,deque,Iphone,Objective C,Uitableview,Deque,此代码运行良好的原因: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifi

此代码运行良好的原因:

- (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语句时,此代码才能正常工作。换句话说,为什么标签上有正确的文本?

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


在屏幕上看到5行左右基本上是可以的,但一旦开始滚动,就会看到一些“有趣”的东西:)

所创建的单元格被重用。这意味着对象被标记为可重用(从而保存对象的完整创建)

因此,一旦滚动出屏幕,一个单元格就被标记为可重用。因此,在创建新单元格之前,首先检查是否存在任何可重用单元格([tableView dequeueReusableCellWithIdentifier:)


您需要设置的文本,因为它(可能)与表中的每个单元格不同,但与对象创建/销毁无关。

即使您来回滚动表视图,所有单元格的值都是正确的?或者仅适用于当前可见的单元格?