Created
January 16, 2016 08:57
-
-
Save czwen/eddb5346fb1d778d9361 to your computer and use it in GitHub Desktop.
hide tableview search bar when init
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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