0

我想做一个看起来像这样的应用程序。

在此处输入图像描述

有很多关于如何使 uitableviewcell 的高度动态化的帖子,所以这对我来说不是问题。我的问题是他们如何将单元格分成具有不同字体的两列?是否有教程或示例如何在 uitableview 中实现?

4

2 回答 2

3

它看起来像一个带有两个标签的自定义单元格。

以下是基本步骤:

  1. 为它创建一个新表和一个 UITableViewController 子类。(我假设你知道如何做这部分,因为你说你可以做可变高度的行。)
  2. 单击原型单元格并选择属性检查器。
  3. 将您的标识符(重用标识符)设置为一个值。让我们将其设置为“TwoLabelCell”
  4. 将两个标签拖到原型单元格上,并将它们排列在您想要的位置。
  5. 将每个标签的字体设置为您想要的方式
  6. 将每个标签的标签设置为不同的值,以便您以后识别它们。在这种情况下,让我们将左侧的设置为 1000,将右侧的设置为 1001。
  7. 在您的自定义类中,实现以下方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TwoLabelCell";
    UITableViewCell *cell           = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    UILabel *leftLabel  = (UILabel *)[cell viewWithTag:1000];
    UILabel *rightLabel = (UILabel *)[cell viewWithTag:1001];

    // Set the values based on the indexPath.  This is just an example.
    leftLabel.text      = @"409";
    rightLabel.text     = @"Vandals and Alans cross the Pyrenees and appear in Hispania.";
}

如果您将与各个行进行大量交互,您可能需要子类化并为每个标签设置属性。(即cell.yearLabel和cell.descriptionLabel)

于 2012-10-29T19:17:50.733 回答
0

嗨,您可以通过为自定义 tableviewcell 添加两个标签来获得此信息,请参阅此链接Custom UITableViewCell Using Interface Builder

于 2012-10-29T20:29:35.097 回答