在iOS7中重新加载tableView标头 [英] Reloading tableView header in ios7
本文介绍了在iOS7中重新加载tableView标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不重新加载所有表的情况下做到这一点?
How can I do it without reloading all table?
-(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, 0, 270, 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;
}
推荐答案
您必须重新加载整个部分才能重新加载标题.
You have to reload the whole section to reload the header.
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation: UITableViewRowAnimationAutomatic];
OR
您可以抓住该视图的手柄并手动更新它:
You could grab a handle to the view and update it manually:
UIView *headerView = [self.tableView headerViewForSection:section];
//... update your view properties here
[headerView setNeedsDisplay];
[headerView setNeedsLayout];
这篇关于在iOS7中重新加载tableView标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文