在UITableView中,cell.detailTextLabel.text无效......为什么?

Rob*_*rtL 42 iphone uitableview

tableView:cellForRowAtIndexPath:我有以下几点:

cell.textLabel.text = @"label";
cell.detailTextLabel.text = @"detail";
Run Code Online (Sandbox Code Playgroud)

这些textLabel节目如预期的那样,但detailTextLabel根本没有出现,尽管没有诊断.我所期望的是"细节"文本将出现在第二行的单元格中,低于"普通"文本,可能具有较小的字体大小.

在这里的另一个帖子中询问同样的问题,用户"jbrennan"回答说tableview单元格样式必须是其他的UITableViewCellStylePlain.但是,似乎只有两种可能的样式,UITableViewCellStylePlain并且UITableViewCellStyleGrouped.我得到相同的结果(细节标签没有出现).

我在文档中没有看到另一种单元格样式吗?UITableView上次更新中是否有更改并且detailTextLabel不再可用?我是否必须做一些额外的事情才能让它出现?有什么建议?

我正在使用xcode 3.2.5并为iPhone 4.2模拟器构建.

Aur*_*ila 117

您的初始化需要更改为:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
reuseIdentifier:CellIdentifier] autorelease];
Run Code Online (Sandbox Code Playgroud)

我强调并加粗了你需要改变的部分.

  • 这似乎每次都会初始化一个新的UITableViewCell,而不是从堆栈中出队以保留内存.似乎重用UITableViewCellStyleSubtitle样式的单元格的唯一方法是子类化,覆盖初始化程序,并调用通常的`[tableView dequeueReusableCellWithIdentifier:@"ReuseIdentifier"];`任何人都可以确认或否认这个吗?请参阅有关`initWithStyle:reuseIdentifier:`https://developer.apple.com/library/ios/documentation/Uikit/reference/UITableViewCell_Class/index.html#//apple_ref/occ/instm/UITableViewCell/initWithStyle:reuseIdentifier的讨论: (3认同)

W D*_*son 14

分配时,需要将单元格类型设置为Subtitle.

if (!cell) {
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:BasicCellIdentifier];
}
Run Code Online (Sandbox Code Playgroud)


小智 12

使用Xcode 4.2时,在"故事板"中将"表视图单元格"样式设置为"字幕".dequeueReusableCellWithIdentifier将返回一个实例化的单元格.