【问题标题】:Label not displaying in UITableView [duplicate]标签未显示在 UITableView [重复]
【发布时间】:2023-03-15 02:40:02
【问题描述】:
-viewDidLoad {
    tbl.rowHeight = 150;
    ary = [[NSArray alloc]initWithObjects:@"asdf",@"asd",nil];
    ary2 = [[NSArray alloc]initWithObjects:@"google",@"yahoo",nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [ary count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    // Configure the cell.
    cell.textLabel.text = [ary objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [ary2 objectAtIndex:indexPath.row] ;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
         return cell;
}

对我来说,问题是 detailtextlabel 没有显示在表格视图中。我的代码有错误吗?

【问题讨论】:

    标签: iphone cocoa-touch uitableview


    【解决方案1】:

    你必须将单元格 styleSubtitle 设置为 subtitle 如下所示

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

    【讨论】:

      【解决方案2】:

      请确保您使用 UITableViewCellStyle 任何东西,但不是 UITableViewCellStyleDefault 应该这样工作,请参阅此了解更多详细信息:

      cell.detailTextLabel.text not working... why

      【讨论】:

        【解决方案3】:

        将 uitableviestyltDEfault 更改为 uitableviewStyleSubtitle

        【讨论】:

          【解决方案4】:

          【讨论】:

          • 这应该是重复关闭的投票,而不是答案。
          【解决方案5】:

          UITableViewCellStyleDefault 之外的任何内容都应与detailLabel 一起使用。

          【讨论】:

            【解决方案6】:

            在单元格的 contentView 上添加 detailtextLabel。

            【讨论】:

              猜你喜欢
              • 2022-01-10
              • 1970-01-01
              • 2020-11-01
              • 1970-01-01
              • 1970-01-01
              • 2023-03-13
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多