草庐IT

ios - dequeueReusableCellWithIdentifier 总是返回非零?

coder 2024-01-10 原文

在下面的经典模式中,从 dequeueReusableCellWithIdentifier 返回的 cell 总是非 nil。为什么?难道我们不应该先分配一些单元格,然后再使用一些单元格吗?

我正在使用自定义单元格,它是在 Storyboard中创建的。 (但是,如果我使用默认的 UITableViewCell ,现象是一样的——返回的单元格仍然总是 non-nil)。

环境:Xcode 4.3.3 iOs 5.1

AlbumListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AlbumCell"];

//cell always non nil --- why??
if(cell == nil){
    cell = [[AlbumListCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"AlbumCell"];

}

最佳答案

如果您正在使用 Storyboard并将 UITableViewCell 的标识符设置为您在 Storyboard文件中的 dequeueReusableCellWithIdentifier(在您的情况下为“AlbumCell”)中使用的标识符,则 UITableView 将始终为您创建单元格。我想这是 Storyboard的一个特点。如果在 Storyboard中找不到标识符,则需要手动创建单元格。

关于ios - dequeueReusableCellWithIdentifier 总是返回非零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11788197/

有关ios - dequeueReusableCellWithIdentifier 总是返回非零?的更多相关文章

随机推荐