DetailTextLabel表现得很奇怪

时间:2014-12-06 13:06:26

标签: ios objective-c uitableview

我正在尝试在UITableViewCell上设置字幕标签。我有一个包含标题和副标题对的字典,密钥列表存储在self.results中。但是,当我使用以下代码运行时:

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Search Result Cell" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Search Result Cell"];
    }
    cell.textLabel.text = [self.results objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = self.resultPairs[[self.results objectAtIndex:indexPath.row]];
    NSLog(@"%@", self.resultPairs[cell.textLabel.text]);

字幕保持空白,但NSLog打印正确的输出。这里发生了什么?当我将detailTextLabel设置为常量时,它可以正常工作。

2 个答案:

答案 0 :(得分:0)

问题是默认的单元格样式不包含副标题。如果您使用的是故事板,则只需在Interface Builder中将样式设置为Subtitle。

答案 1 :(得分:0)

解决方案结果是字符串包含大量初始空格,导致它们被填充到视图之外。