当我使用以下代码段时,详细文本标签不会显示:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier = @"NEW";
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath ];
if(cell==nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
NSDictionary* item = [saleItems objectAtIndex:[indexPath row]];
cell.textLabel.text = [item valueForKey:@"name"];
cell.detailTextLabel.text = [item valueForKey:@"store"];
return cell;
}
但是,当我将上述方法修改为以下内容时,显示了详细文本:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier = @"NEW";
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
NSDictionary* item = [saleItems objectAtIndex:[indexPath row]];
cell.textLabel.text = [item valueForKey:@"name"];
cell.detailTextLabel.text = [item valueForKey:@"store"];
return cell;
}
第一种方法出了什么问题?
使用dequeueReusableCellWithIdentifier的正确方法是什么?
最佳答案
根据此SO post,注册UITableViewCell
意味着将使用默认样式实例化所有单元格。 registerClass:forCellReuseIdentifier:
无法使用带字幕的左右详细信息单元格。
关于ios - detailtext标签未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18393478/