dequeueReusableCellWithIdentifier总是返回非零? [英] dequeueReusableCellWithIdentifier always return non nil?

查看:90
本文介绍了dequeueReusableCellWithIdentifier总是返回非零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dequeueReusableCellWithIdentifier 返回的单元格下方的经典模式中,始终为非 nil 。为什么?我们不应该首先分配一些单元格,然后我们可以重新使用一些单元格吗?

In the classic pattern below the returned cell from dequeueReusableCellWithIdentifier is always non nil. Why? Shouldn't we have to allocated some cell first then we can have some to be reused?

我使用的是自定义单元格,它是在故事板中创建的。 (但是,如果我使用了默认的UITableViewCell,现象是相同的 - 返回的单元格仍然总是非零)。

I am using a customize cell and it was created in the storyboard. (However, if I had used the default UITableViewCell ,the phenomena is same - the returned cell is still always non-nil).

环境:Xcode 4.3.3 iOs 5.1

Enviroment: 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"];

}


推荐答案

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

If you're using storyboard and set the UITableViewCell's Identifier to the identifier to the one you are using in dequeueReusableCellWithIdentifier ("AlbumCell" in your case) in the storyboard file, the UITableView will always create cells for you. I guess this is a feature of storyboard. If the identifier can't be found in your storyboard, then you need to create cells manually.

这篇关于dequeueReusableCellWithIdentifier总是返回非零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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