【问题标题】:UITableView with two Columns but not two different TableViewsUITableView 有两列但不是两个不同的 TableView
【发布时间】:2012-03-12 17:55:40
【问题描述】:

我正在处理一个要求,我需要一个 TableView 有两列,它们不应该相互独立。因此,我不是在寻找两个独立滚动的 TableView,而是在寻找两个可以一起滚动的列的单个 TableView。在每一列中,我再次需要填写数据和屏幕截图。

到目前为止,我已经修改了 cellForRowAtIndexPath 中的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";
    static NSString *secondCellIdentifier = @"Cell2";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    UITableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:secondCellIdentifier];

    if (cell2 == nil) {
        cell2 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:secondCellIdentifier] autorelease];
    }

    // Configure the cell...

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

    cell.textLabel.text = [tableList objectAtIndex:indexPath.row];

    cell2.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

    cell2.textLabel.text = [tableList2 objectAtIndex:indexPath.row];

    UITableViewCell *twoColumnRowView = [[UITableViewCell alloc]init];

    [twoColumnRowView addSubview:cell];
    [twoColumnRowView addSubview:cell2];

    return twoColumnRowView;
}

但不幸的是,我没有得到一个两列的表格,而是得到了一个奇怪的输出,可以在屏幕截图中看到。

谁能指引我正确的方向。

附:我在同一个论坛和互联网上浏览过关于同一主题的先前帖子,但没有任何适当的解释或示例。最好能得到有用的信息。

谢谢

【问题讨论】:

    标签: objective-c ipad ios5 xcode4.2


    【解决方案1】:

    您必须创建一个具有您正在寻找的布局的自定义 UITableViewCell。然后可以在tableView:cellForRowAtIndexPath:方法中实例化它

    【讨论】:

    • 但我在 tableView:cellForRowAtIndexPath: 方法中做了同样的事情。如果我错了,请纠正我。另一方面,如果您有任何示例,那就太好了
    【解决方案2】:

    制作您的自定义 UITableViewCell 类。在单元格内放置两个 UIButton 并根据您的布局设置它们。

    【讨论】:

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