ストーリーボードを使用して iPad 6.0 でアプリケーションを開発しています。
まず、私の目標を説明させてください。2 つの UITableViewControllers を使用して、Master-Detail (SplitViewController のような) ビュー コントローラーを実現しようとしています。
最初の UITableView("Master") は、名前が示すように、このHeaderTableViewと呼びましょう...
...2 番目の UITableView("Detail")、これをEncodingTableViewと呼びましょう。これには、プログラムによって変更される CustomTableViewCell が含まれます (各セルに含まれるサブビューは、UITextField、UIButton、または UISwitch の場合があります)。
EncodingTableView.mを参照してください。
- (void)updateEncodingFields:(NSArray *)uiViewList
{
// Add logic for determining the kind of UIView to display in self.tableView
// Finally, notify that a change in data has been made (not working)
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *encodingFieldsTableId = @"encodingFieldsTableId";
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:encodingFieldsTableId];
if (cell == nil) {
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:encodingFieldsTableId];
}
// Change text in textView property of CustomTableViewCell
cell.encodingFieldTitle.text = uiViewList.title;
// added methods for determining what are to be added to [cell.contentView addSubView:]
// data used here is from the array in updateEncodingFields:
}
私のHeaderTableView.mには、 EncodingTableViewを更新するための didSelectRowAtIndexPath が含まれています
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (![selectedIndexPath isEqual:indexPath]) {
selectedIndexPath = indexPath;
[self updateDataFieldTableViewForIndexPath:indexPath];
}
}
- (void)updateDataFieldTableViewForIndexPath:(NSIndexPath *)indexPath {
[self.encodingTableView updateEncodingFields:self.uiViewList];
}
質問
- データはすべて問題ありませんが、EncodingTableViewがフィールドを「再描画」しないのはなぜですか? 細胞の再利用がこれと関係があるのではないかと疑っていますが、その理由はわかりません.
結果のスクリーンショット:
HeaderTableView での初期選択
HeaderTableView での 2 番目の選択
私が試したこと:
- [UITableView setNeedsDisplay]、[UITableView reloadData]、[UITableView setNeedsLayout] などの提案が表示され続けましたが、どれも機能しませんでした。
- tableViewCells の再利用を削除すると問題なく動作しますが、これにより CustomTableView.encodingFieldTitle の一部が消えます。言うまでもなく、再利用セルを削除すると、パフォーマンスの問題が発生する可能性があります。
制限: SplitViewController を使用することをお勧めしますが、これはアプリの一部にすぎません (したがって、RootViewController ではありません)。
最後に、長い記事を読んでくれてありがとう。;)