如何在不重新加载所有表的情况下执行此操作?
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *header; if(!self.searchBar) { self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,10,270,kRowHeight)]; self.searchBar.delegate = self; self.searchBar.barStyle = UISearchBarStyleDefault; self.searchBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; self.searchBar.barTintColor = [UIColor clearColor]; } if(!self.placeholderSearchBarView) { self.placeholderSearchBarView = [[UIView alloc]initWithFrame:CGRectMake(0,kSearchBarPlaceholderHeight)]; self.placeholderSearchBarView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:0.7]; } if (self.showSearchBar) { for (UIView *v in self.tableView.tableHeaderView.subviews) { if (v.tag == 3433) { [v removeFromSuperview]; } } header = self.searchBar; } else { header = self.placeholderSearchBarView; } return header; }
解决方法
您必须重新加载整个部分才能重新加载标题.
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation: UITableViewRowAnimationAutomatic];
要么
您可以抓取视图的句柄并手动更新它:
UIView *headerView = [self.tableView headerViewForSection:section]; //... update your view properties here [headerView setNeedsDisplay]; [headerView setNeedsLayout];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。