在iOS 8 xcode 6中不显示DetailTextLabel

时间:2014-10-30 10:01:56

标签: ios xcode cell detailtextlabel

我制作了关于运行iPhone 5S,Xcode 6和iOS 8的教程。我想在单元格表中显示textDetailLabel。你能帮我解决一下这里的问题吗?我已经检查了语法,但它没有工作

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
Checklist *checklist = [self.dataModel.lists objectAtIndex:indexPath.row];
cell.textLabel.text = checklist.name;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

int count = [checklist countUncheckedItems];
if ([checklist.items count] == 0) {
    cell.detailTextLabel.text = @"(No Items)";
} else if (count == 0) {
    cell.detailTextLabel.text = @"All Done!";
} else {
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%d Remaining", count];
}
return cell;

}

1 个答案:

答案 0 :(得分:2)

  1. 移动

    static NSString * CellIdentifier = @" Cell";

  2. 在方法之外,公开。

    1. 创建表格视图时,请在创建表格的位置写下此行(在viewDidLoad或您创建表格的方法中)
    2. [dataTable registerClass:[UITableViewCell class] forCellReuseIdentifier:tableIdentifier];

      1. 中删除单元格条件
        • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      2. 方法,因为您的表格视图单元格不是nil,您无法设置单元格样式。

        所以你必须写

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