Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView contentOffSet is not working properly

Tags:

In viewWillAppear, I have added UISearchBar as my headerview of UITableView. When view loads, I hides UISearchbar under UINavigationBar using contentOffSet of UITableView. When user pull down the tableview the searchbar gets displayed.

After adding headerview I hides it using below code.

self.tableView.contentOffset = CGPointMake(0, 40); //My searhbar height is 40 

But at times contentOffSet is not hiding headerview. What can be the mistake.

like image 287
JiteshW Avatar asked Mar 05 '13 11:03

JiteshW


1 Answers

This worked for me:

// contentOffset will not change before the main runloop ends without queueing it, for iPad that is dispatch_async(dispatch_get_main_queue(), ^{     // The search bar is hidden when the view becomes visible the first time     self.tableView.contentOffset = CGPointMake(0, CGRectGetHeight(self.searchBar.bounds)); }); 

Put it in your -viewDidLoad or -viewWillAppear

like image 151
maz Avatar answered Sep 27 '22 22:09

maz