代码之家  ›  专栏  ›  技术社区  ›  ComSubVie

UITableView中的可编辑tableHeaderView(如联系人应用程序)

  •  1
  • ComSubVie  · 技术社区  · 14 年前

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

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

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

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

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

    2 回复  |  直到 14 年前
        1
  •  1
  •   iPhoneDollaraire    14 年前

    我也这么做过(尽管在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;
    }
    
        2
  •  0
  •   Hoang Pham    14 年前

    您正在尝试做的是非常标准的,考虑在UITababVIEW DATABOSCE中实现这些协议,特别是TITLE FoeHealErnReals&提交方式:

    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的类型为“组”,而不是“普通”。

    推荐文章