1

現在、グループ化された UITableView を使用して編集可能な詳細ビューを実装しようとしています。連絡先アプリケーションのようにしたい:

  • 表示状態では、ヘッダーをプレーン ラベルとして表示する必要があります (連絡先では、透明な背景を持つ名前です)。
  • 編集状態では、ヘッダーを編集可能な UITableViewCell として表示する必要があります (Contact の tableHeader? は、背景が透明なプレーン テキストから背景が白い標準の UITableViewCell に変わります)。

これを達成するための最良の方法が何であるかはよくわかりません。最初に、ヘッダーを UILabel tableHeaderView として追加しようとしましたが (これはうまく機能します)、これを UITableViewCell に切り替えることはできません。編集モードに入るとき、ヘッダーを削除して新しいセクションを追加する可能性があります。

現在、常に UITableViewCell を使用して表示モードで透明にし、編集モードでデフォルトに切り替えようとしています。ただし、UITableViewCell(UITableViewCellStyleDefaultにある)のUILabelを透明にすることはできませんでした(ただし、UITableViewCellを透明にすることはできましたが、その中のtextLabelはできませんでした)。

この動作を実装する最良の方法は何ですか?

4

2 に答える 2

1

私もこれを行いました (ただし、iOS4 の連絡先アプリへの変更には問題があります!) 私のソリューションでは 2 つの異なるヘッダー ビューを使用し、以下に基づいてそれらを切り替えます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のタイプをPlainではなくGroupとして選択することを忘れないでください。

于 2010-03-01T13:58:05.270 に答える