简体   繁体   English

table中的搜索栏查看并重新加载数据

[英]Searchbar in tableView and reload data

I can not search because my search bar is a header of tableView and then I reload tableView I have not search results. 我无法搜索,因为我的搜索栏是tableView的标题,然后重新加载tableView我没有搜索结果。

I know there is a lot of ways to solve it but what is more wisely? 我知道有很多解决方法,但是更明智的选择是什么?

My code 我的密码

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)sectionIndex
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 10, 270, kRowHeight)];
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 270, kRowHeight)];
self.searchBar.delegate = self;
view.opaque = NO;
view.backgroundColor = [UIColor clearColor];
self.searchBar.opaque = NO;
self.searchBar.translucent = NO;
self.searchBar.backgroundColor = [UIColor clearColor];
[view addSubview: self.searchBar];
self.searchBar.barStyle = UISearchBarStyleDefault;
self.searchBar.autoresizingMask =  UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin ;
self.searchBar.barTintColor = [UIColor clearColor];

return view;

} }

And I want that then I scroll tableView my searchBar will disappear in top and then I scroll up it will appear. 我想要那然后我滚动tableView我的searchBar将消失在顶部,然后向上滚动它将出现。 Is any simple to do it? 有什么简单的方法吗?

You need to use tableHeaderView and not section header. 您需要使用tableHeaderView而不是节标题。 Just put in your viewDidLoad 只需放入您的viewDidLoad

UISearchBar* searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 270, kRowHeight)];
self.tableView.tableHeaderView = searchBar;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM