Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide UISearchBar below UINavigationBar after cancelButton was called

Tags:

I'm typically using [self.tableView setContentOffset:CGPointMake(0,40)]; in order to hide the UISearchBar (that I set as header of the tableView) below the navigationBar. Everything works well in viewDidLoad: the searchBar is below the navigationBar when the view is loaded. Then I put the same line of code

[self.tableView setContentOffset:CGPointMake(0,40)]

in

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller

but it does anything: the searchBar remain visible when cancel Button is clicked. What's wrong?

like image 863
giampo Avatar asked Nov 12 '09 19:11

giampo


2 Answers

The following method should do it:

-(void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller{
    [self.tableView setContentOffset:CGPointMake(0,40)];    
}
like image 99
Ben Avatar answered Oct 12 '22 12:10

Ben


Is the method below being called from the main thread?

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller

You can check like this:

if ([NSThread isMainThread]) {
    NSLog(@"Yes it is the main thread.");
}

Otherwise, any view changes will not register on screen. If you must modify the view from a separate thread you can use this:

[self performSelectorOnMainThread:@selector(XXX) withObject:nil waitUntilDone:NO];

I'm not sure if that's your issue, but it's where I'd start to look.

like image 43
Sangraal Avatar answered Oct 12 '22 13:10

Sangraal