簡體   English   中英

table中的搜索欄查看並重新加載數據

[英]Searchbar in tableView and reload data

我無法搜索,因為我的搜索欄是tableView的標題,然后重新加載tableView我沒有搜索結果。

我知道有很多解決方法,但是更明智的選擇是什么?

我的密碼

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

}

我想要那然后我滾動tableView我的searchBar將消失在頂部,然后向上滾動它將出現。 有什么簡單的方法嗎?

您需要使用tableHeaderView而不是節標題。 只需放入您的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