在ios7中重新加载tableView标头

在ios7中重新加载tableView标头,ios,uitableview,tableview,Ios,Uitableview,Tableview,如何在不重新加载所有表的情况下执行此操作 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *header; if(!self.searchBar) { self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 10, 270, kRow

如何在不重新加载所有表的情况下执行此操作

-(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;
}
你需要使用

因此,当您需要更新标题时:

NSIndexSet *headers = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [self.tableView numberOfSections])];
[self.tableView reloadSections:headers withRowAnimation:UITableViewRowAnimationAutomatic];
如果你只有一个部分(正如你刚刚在更新的问题中提到的),你可以打电话

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];

您必须重新加载整个节才能重新加载标题

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation: UITableViewRowAnimationAutomatic];

您可以抓取视图的句柄并手动更新它:

UIView *headerView = [self.tableView headerViewForSection:section];
//... update your view properties here
[headerView setNeedsDisplay];
[headerView setNeedsLayout];

我知道你放了标题,但你是说标题还是节标题?还可以在设置标题的地方发布一些代码please@Rich,我更新我的帖子,我有一个部分,it部分标题,第二种方法我需要如何设置tableView标题?它不工作,如果我使用self.tableView.tableHeaderView=headerView;[self.tableView.tableHeaderView设置需要显示];[self.tableView.tableHeaderView setNeedsLayout]@用户3527777在我开始之前-您打算如何处理
tableView:viewForHeaderInSection:
方法中的
tableHeaderView
?我的计划是:1.在scrollViewDidScroll中获取滚动偏移tableView并设置标志(向上或向下滚动)2。在scrollViewDidScroll中调用重新加载标题。3.在ViewForHeaderSection中在headerI中加载所需视图如果只有一个分区,我看不出为什么不使用
tableHeaderView
?然后,当您想要更改标题时,只需将新视图设置为
tableHeaderView
。您使用的节头实际上是一个包含多个节的表的节头。我认为
tableHeaderView
更适合您的需要:)您的意思是我可以将View设置为tableView.tableHeaderView?是的,我试过了,但我也无法从ScrollViewDidScroll重新加载它。您不需要重新加载它(除非它包含一些数据-然后只需在其上设置新值),只需将另一个视图(一个
self.searchBar
self.placeholderSearchBarView
)设置为
tableHeaderView