Jim*_*med 5 spacing uitableview ios tableheader
我有一个UITableViewController,如果满足某些条件,将显示表视图标题(NOT节标题).在加载时显示带或不带标题视图的控制器都可以正常工作.但是如果我显示标题,然后将其删除,则每次都会将间距(标题框的位置)保留在表格视图的顶部.
我在删除表视图标题时没有运气,尝试了以下各种组合:
[self.tableView beginUpdates];
self.tableView.tableHeaderView = nil;
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
[self.tableView reloadData];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
还有其他人遇到过吗?
表视图标题代码:
- (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];
}
}
Run Code Online (Sandbox Code Playgroud)
看来这是一个iOS错误,这是删除tableHeaderView的当前解决方法,它的间距直到修复:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.tableView.bounds), 1.0f)];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1021 次 |
| 最近记录: |