Note that there are some explanatory texts on larger screens.

plurals
  1. POHide UIToolBar when using an UISearchBar
    primarykey
    data
    text
    <p>Hello I'm currently encountering a problem when I try to hide a toolBar With a searchBar.</p> <p>I have a modal view with an UIToolBar, an UISearchBar (and its controller) and an UITableView. I am using a UIToolbar because this view is actually displayed as a modal view. I guess that what I am trying to do would a bit easier in the context of a UINavigationController. </p> <p>When searching, I want to hide the toolBar. For this I use notifications to change the frame of my components when the keyboard appears. But I have a problem, there is an highlighted space under my searchBar. You can see a screenshot :</p> <p><a href="http://dl.dropbox.com/u/39339665/Capture%20d%E2%80%99%C3%A9cran%202011-10-19%20%C3%A0%2016.21.43.png" rel="nofollow">http://dl.dropbox.com/u/39339665/Capture%20d%E2%80%99%C3%A9cran%202011-10-19%20%C3%A0%2016.21.43.png</a></p> <p>Are is were I use NSNotifcationCenter to get notified when the keyboard will be hidden/shown:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } </code></pre> <p>Here are my callback:</p> <pre><code>- (void)keyboardWillHide:(NSNotification *)notification { [UIView beginAnimations:nil context:nil]; CGRect toolbarFrame = self.toolBar.frame; toolbarFrame.origin.y += toolbarFrame.size.height; CGRect tableViewFrame = self.theTableView.frame; tableViewFrame.origin.y += toolbarFrame.size.height; tableViewFrame.size.height -= toolbarFrame.size.height; self.toolBar.frame = toolbarFrame; self.theTableView.frame = tableViewFrame; [UIView commitAnimations]; } - (void)keyboardWillShow:(NSNotification *)notification { [UIView beginAnimations:nil context:nil]; CGRect toolbarFrame = self.toolBar.frame; toolbarFrame.origin.y -= toolbarFrame.size.height; CGRect tableViewFrame = self.theTableView.frame; tableViewFrame.origin.y -= toolbarFrame.size.height; tableViewFrame.size.height += toolbarFrame.size.height; self.toolBar.frame = toolbarFrame; self.theTableView.frame = tableViewFrame; [UIView commitAnimations]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload