Skip to content

Instantly share code, notes, and snippets.

@czwen
Created January 16, 2016 08:57
Show Gist options
  • Save czwen/eddb5346fb1d778d9361 to your computer and use it in GitHub Desktop.
Save czwen/eddb5346fb1d778d9361 to your computer and use it in GitHub Desktop.
hide tableview search bar when init
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
CGPoint contentOffset = self.tableView.contentOffset;
contentOffset.y += CGRectGetHeight(self.tableView.tableHeaderView.frame);
self.tableView.contentOffset = contentOffset;
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if (!self.tableView.tableHeaderView) {
@weakify(self);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@strongify(self);
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0., 0., 320., 44.)];
CGPoint contentOffset = self.tableView.contentOffset;
contentOffset.y += CGRectGetHeight(searchBar.frame);
self.tableView.contentOffset = contentOffset;
self.tableView.tableHeaderView = searchBar;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment