繁体   English   中英

在iOS 8 xcode 6中不显示DetailTextLabel

[英]DetailTextLabel is not display in iOS 8 xcode 6

我在运行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. 移动

    静态NSString * CellIdentifier = @“ Cell”;

淘汰方法,将其公开。

  1. 创建表视图时,在创建表的地方(在viewDidLoad或创建表的方法中)写此行

[dataTable registerClass:[UITableViewCell class] forCellReuseIdentifier:tableIdentifier];

  1. 从中删除细胞状况

    • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

方法,因为您的表格视图单元格不是nil,并且您无法设置单元格样式。

所以你必须写

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM