gpt4 book ai didi

ios - 在 ios7 中重新加载 tableView header

转载 作者:技术小花猫 更新时间:2023-10-29 11:15:03 24 4
gpt4 key购买 nike

如何在不重新加载所有表格的情况下做到这一点?

-(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;
}

最佳答案

您必须重新加载整个部分才能重新加载标题。

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

您可以获取 View 的句柄并手动更新它:

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

关于ios - 在 ios7 中重新加载 tableView header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23041214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com