2010-02-27 19 views
32

使用下面的代码我得到text.label而不是detailTextLabel.text。 NSLog显示正确。cell.detailTextLabel.text not working ... why

cell.textLabel.text = [eventLabels objectAtIndex:indexPath.row]; 
cell.detailTextLabel.text = [eventFields objectAtIndex:indexPath.row]]; 

NSLog(@"%@", [eventFields objectAtIndex:indexPath.row]); 

我也试过......

cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", [eventFields objectAtIndex:indexPath.row]];  

我以前没有这个问题。有什么建议么?

约翰

回答

83

确保您使用适当的UITableViewCellStyle本(除了UITableViewCellStyleDefault应该这样工作)。单元格的样式在初始化时指定。

+0

这是它!!!!我正在使用,但UITableViewCellStyleDefault。我想我使用了当我创建课程时没有考虑到的内容。非常感谢。 约翰 – user278859 2010-02-27 23:18:25

+10

user278859:如果John已经回答了你的问题,那么请接受他的回答。如果你不接受正确的答案,有什么用? – 2010-11-11 08:26:20

+0

像魔术一样工作 – 2011-04-03 11:28:10

24
- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
            reuseIdentifier:CellIdentifier] autorelease]; 
} 

请记住改为UITableViewCellStyleSubtitle

2

如果你选择的风格UITableViewCellStyleSubtitle,你detailTextLabel.text将显示

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
           reuseIdentifier:CellIdentifier] ; 

UITableView Source