1

我目前正在尝试使用分组的 UITableView 实现可编辑的详细信息视图。我希望它看起来像联系人应用程序:

  • 在查看状态下,它应该将标题显示为普通标签(在联系人中,它是具有透明背景的名称)。
  • 在编辑状态下,它应该将标题显示为可编辑的 UITableViewCell(在联系人的 tableHeader? 中,从具有透明背景的纯文本更改为具有白色背景的标准 UITableViewCell)。

我不确定实现这一目标的最佳方法是什么。首先,我尝试将标题添加为 UILabel tableHeaderView(效果很好),但随后我无法将其切换到 UITableViewCell。一种可能是在进入编辑模式时删除标题并添加新部分。

目前我正在尝试始终使用 UITableViewCell 并使其在查看模式下透明并在编辑模式下将其切换为默认值。但是,我无法使 UITableViewCell(在 UITableViewCellStyleDefault 中)的 UILabel 透明(尽管我确实设法使 UITableViewCell 透明,但不是其中的 textLabel)。

实现此行为的最佳方法是什么?

4

2 回答 2

1

我也这样做了(尽管 iOS4 中联系人应用程序的更改尚无争议!)我的解决方案使用两个不同的标题视图并根据以下内容在它们之间切换isEditing

- (UIView *)infoHeaderAnimated:(BOOL)animated {
    UIView *header = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 90.0)] autorelease];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(98.0, 41.0, 221.0, 21.0)];
    label.font = [UIFont boldSystemFontOfSize:17.0];
    label.backgroundColor = [UIColor clearColor];
    label.text = baseEntity.labelText;
    [header addSubview:label];
    [label release];
    return header;
}

- (UIView *)editingHeaderAnimated:(BOOL)animated {
    UIView *header = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 90.0)] autorelease];
    UITableView *tv = [[UITableView alloc] initWithFrame:CGRectMake(78.0, 10.0, 240.0, 90.0) style:UITableViewStyleGrouped];
    tv.backgroundColor = [UIColor clearColor];
    tv.dataSource = self;
    tv.delegate = self;
    tv.rowHeight = 62.0;    //@@@ height of cell and frame depend on elements
    tv.tag = kEditingHeaderTag;
    editingHeaderTableView = [tv retain];
    [header addSubview:tv];
[tv release];   
    return header;
}
于 2010-07-04T18:55:48.850 回答
0

您正在尝试做的是非常标准的,请考虑在 UITableViewDatasource 中实现这些协议,尤其是 titleForHeaderInSection 和 commitEditingStyle:

Configuring a Table View
– tableView:cellForRowAtIndexPath:  required method
– numberOfSectionsInTableView:
– tableView:numberOfRowsInSection:  required method
– sectionIndexTitlesForTableView:
– tableView:sectionForSectionIndexTitle:atIndex:
– tableView:titleForHeaderInSection:
– tableView:titleForFooterInSection:

Inserting or Deleting Table Rows
– tableView:commitEditingStyle:forRowAtIndexPath:
– tableView:canEditRowAtIndexPath:

请记住在 Interface Builder 中将 TableView 的类型选择为 Group 而不是 Plain。

于 2010-03-01T13:58:05.270 回答