ios - detailtext标签未显示

标签 ios uitableview uikit

当我使用以下代码段时,详细文本标签不会显示:

-(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/

相关文章:

objective-c - 删除自定义 UITableviewCell 边框

animation - 处理 iOS 10 中的 AutoLayout 约束动画差异?

iphone - iOS 按住手势 + 点击

iphone - 核心数据/NSFetchedResultsController错误

ios - 在 swift 中为多维数组添加数组扩展?

ios - 如何在测试框架中测试 NSLog(默认 iOS)

ios - 重试 RACObserve 直到成功

iphone - 在 ios 中点击节标题时,在节中折叠展开行

ios - 似乎无法将数组传递给 uitableview xcode

ios - UITableView 清除背景