特定の条件を満たす場合は、表のビューヘッダー(セクションヘッダーではありません)を表示するUITableViewControllerがあります。ロード時にヘッダービューの有無にかかわらずコントローラーを表示するだけで問題ありません。しかし、ヘッダーを表示してから削除すると、ヘッダーのフレームが配置されていた間隔が毎回テーブルビューの一番上にとどまります。UITableView - ビューが削除された場合に表の見出しの間隔が表示されます。
運とテーブルビューのヘッダを削除するとき、私は、次のすべての組み合わせを試してみました:他に
[self.tableView beginUpdates];
self.tableView.tableHeaderView = nil;
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
[self.tableView reloadData];
[self.tableView endUpdates];
誰もがこのに遭遇しましたか?
表ビューのヘッダーコード:
- (void)updateTableHeaderView
{
if (self.alerts.count && self.isViewLoaded) {
[self.tableView beginUpdates];
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.tableView.bounds), 40.0f)];
headerView.preservesSuperviewLayoutMargins = YES;
self.tableView.tableHeaderView = headerView;
UIButton *alertButton = [UIButton buttonWithType:UIButtonTypeCustom];
alertButton.tintColor = [UIColor whiteColor];
alertButton.translatesAutoresizingMaskIntoConstraints = NO;
[alertButton setBackgroundImage:[UIImage imageWithColor:alertTintColor] forState:UIControlStateNormal];
[alertButton setBackgroundImage:[UIImage imageWithColor:alertHighlightedTintColor] forState:UIControlStateHighlighted];
[alertButton addTarget:self action:@selector(alertButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:alertButton];
NSDictionary *views = NSDictionaryOfVariableBindings(alertButton);
NSDictionary *metrics = nil;
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[alertButton]|" options:0 metrics:metrics views:views]];
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[alertButton]|" options:0 metrics:metrics views:views]];
[self.tableView endUpdates];
}
else if (self.isViewLoaded) {
[self.tableView beginUpdates];
self.tableView.tableHeaderView = nil;
[self.tableView endUpdates];
}
}
はうまくいきます!!どうぞよろしくお願いしますか? – NSSakly
@ NSSakly必要に応じてテーブルビューヘッダーを生成(および削除)するコードを追加しました。問題は、ヘッダーを表示して(ユーザーがアラートを受け取ったときに)ヘッダーを表示すると、ヘッダーを削除したいということです。しかし、それを取り除くと、ヘッダーがあるスペース(つまり、テーブルの上端と最初のセクション/行の間の隙間)が残されます。 – JimmyJammed