【发布时间】:2015-09-15 21:46:37
【问题描述】:
UITableViewCell detailTextLabel 从不显示。
没有 xib,没有故事板。 我试过 UITableViewCellStyleValue1、UITableViewCellStyleValue2 和 UITableViewCellStyleSubtitle。我没有使用子类 UITableViewCells。我已经尝试过 detailTextLabel.text 和 detailTextLabel.attributedText。我已经验证了重用 ID 没有在其他任何地方使用,并且我已经通过并确认它是正确的值。 textlabel 有效,如果我设置了 accessoryType 也可以。只是detailTextLabel拒绝显示。
值得注意的是,(cell == nil) 条件从不命中,我不知道为什么。我尝试将重用 ID 设置为乱码,以查看它是否会产生任何效果但没有成功。我错过了什么?
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class]
forCellReuseIdentifier:@"reuseCellID"];
[self setTitle:@"Title"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *reuseCellID = @"reuseCellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseCellID
forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:reuseCellID];
cell.detailTextLabel.text = @"detail (one)";
}
cell.textLabel.text = self.collection[indexPath.row];
cell.detailTextLabel.text = @"detail (two)";
/*NSMutableAttributedString *textLabelStr =
[[NSMutableAttributedString alloc] initWithString:@"attributed detail"];
cell.detailTextLabel.attributedText = textLabelStr;*/
return cell;
}
【问题讨论】:
标签: ios objective-c uitableview