UITableViewCell detailTextLabel从不显示。
没有xib,没有故事板。我试过UITableViewCellStyleValue1,UITableViewCellStyleValue2和UITableViewCellStyleSubtitle。我不使用子类UITableViewCells。我试过detailTextLabel.text和detailTextLabel.attributedText。我已经验证了重用ID不在其他任何地方使用,并且我已经通过并确认它是正确的值。textlabel起作用,如果我设置textlabel,accessoryType也能工作。只是detailTextLabel拒绝显示。
值得注意的是,(单元格==为零)条件从未被击中,我不知道为什么。我试着把重复使用的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;
}发布于 2015-09-15 22:08:38
if (cell == nil)永远不会被击中,因为您使用dequeueReusableCellWithIdentifier:forIndexPath:和registerClass: forCellReuseIdentifier:。
摆脱对registerClass: forCellReuseIdentifier:的调用,使用dequeueReusableCellWithIdentifier: (不使用forIndexPath: )。
然后,您的代码将执行您的期望。
顺便说一句,除非您希望每个单元格都有相同的详细文本,否则不要在if (cell == nil)中设置if (cell == nil)。
https://stackoverflow.com/questions/32596215
复制相似问题