これは少し説明するかもしれません。私はUIViewControllerサブクラスをラベルとテーブルビューの下に直接(ラベルと他のいくつかのコントロールは私がUITableViewControllerサブクラスを使用することができない理由である)を含んでいます。テーブルビューの内容は動的なので、追加するとその高さを直接設定できません。だから、私はloadViewで次のようにしています。UIViewControllerで動的にサイズ変更されたテーブルビュー
//add the table view with no size for now
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
tableView.dataSource = self;
tableView.delegate = self;
tableView.scrollEnabled = NO;
//now that the datasource is set, use the delegates to update the height
[tableView layoutIfNeeded];
[tableView setFrame:CGRectMake(0, self.y_position, 320, [tableView contentSize].height)];
//add it to my scrollview, which contains all controls in this view
[scrollView addSubview:tableView];
これはうまくいきます。
ビューの編集モードに入ると問題が発生します。追加のセクションと行を挿入して、テーブルビューの内容を変更したいと思います。それのサイズがいないので
- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
[tableView beginUpdates];
[super setEditing:editing animated:animated];
//insert or remove the section and row
NSRange range = NSMakeRange(0, 1);
if (self.isEditing) {
[tableView insertSections:[NSIndexSet indexSetWithIndexesInRange:range] withRowAnimation:UITableViewRowAnimationAutomatic];
}
else {
[tableView deleteSections:[NSIndexSet indexSetWithIndexesInRange:range] withRowAnimation:UITableViewRowAnimationAutomatic];
}
[nameAndIngredientsTableView endUpdates];
}
追加セクションと行がうまく追加されますが、テーブルビューの一番下の行が切断されています。これまでのところ、私はsetEditingの次の実装を持っています更新されました。私はこれをどのようにするべきですか?
私は再び同じコードを使用しようとしました - layoutIfNeededをし、手動で高さを設定するが、これは私が動的にサイズを変更するために見てしなければならないものを知ってみたいもの
を行うにはいないようです編集中に出入りするときのテーブルビュー。