我制作了关于运行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;
}
答案 0 :(得分:2)
移动
static NSString * CellIdentifier = @" Cell";
在方法之外,公开。
[dataTable registerClass:[UITableViewCell class] forCellReuseIdentifier:tableIdentifier];
从
中删除单元格条件方法,因为您的表格视图单元格不是nil,您无法设置单元格样式。
所以你必须写
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];