2010-02-12 81 views
1

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

  • 在查看状态下,它应该将标题显示为普通标签(在Contacts中它是带有TRANSPARENT背景的名称)。
  • 在编辑状态下,它应该将页眉显示为可编辑的UITableViewCell(在Contact的tableHeader?从纯背景的纯文本变为带有白色背景的标准UITableViewCell)。

我不太确定实现这个目标的最佳方法是什么。首先,我试图添加标题为UILabel tableHeaderView(这很好用),但是我不能将它切换到UITableViewCell。在进入编辑模式时,可能会删除标题并添加新的部分。

目前我试图总是使用UITableViewCell并使其在查看模式下透明,并在编辑模式下将其切换为默认值。但是,我还没有能够使UITableViewCell(UITableViewCellStyleDefault中的UILabel)透明(尽管我设法使UITableViewCell透明,但不是其中的textLabel)。

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

回答

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; 
} 
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: 

记住要选择你的TableView为集团而不是平原类型界面生成器。

+0

谢谢您回答。但是,联系人应用程序似乎使用tableHeader而不是顶部视图的sectionHeader,并将其更改为编辑模式下的标准单元格。或者它使用透明的单元格,在编辑模式下切换到正常状态。 – ComSubVie 2010-03-02 11:33:48

+0

啊,你在谈论详细查看一个联系人时,点击修改?我认为这里没有什么特别的魔力,第一个标题是一个普通的tableview单元格,但是具有自定义样式,它也设置了这个单元格的高度以使感觉不同,但事实上并非如此。 – 2010-03-02 11:57:25

相关问题