从UITableView中取出可重用的单元格

kpo*_*wer 2 iphone objective-c deque uitableview

为什么这段代码工作正常:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

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

nic*_*mro 6

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

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