[英]UITableViewCell subtitle not appearing on load
我有一个带有单元格的表格,其中只有在搜索了某些内容后才出现字幕。 这是cellForRowAtIndexPath
的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if(tableView == self.tableView)
{
// Configure the cell...
cell.textLabel.text = self.objects[indexPath.row];
cell.detailTextLabel.text = @"test2";
}
else{
// Configure the cell...
cell.textLabel.text = self.results[indexPath.row];
cell.detailTextLabel.text = @"test1";
}
return cell;
}
编辑:ArtOfWarfare的答案是正确的。 这是情节提要中的问题。 见下图:
您的代码建议您有两个单独的表...我建议您的问题出在表的配置方式上,可能是在Storyboard中。
您是否愿意,其中一个设置了带有“ Cell”标识符但原型不是UITableViewCellStyleSubtitle的原型? 这样一来,您的单元创建方法就不会在一种方法中调用,而只能在另一种方法中调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.