Search code examples
iphonexcodeuisearchdisplaycontroller

setNavigationBarHidden:YES doesn't work with the searchDisplayController


I'm using the following code to hide my navigationBar in the detailViewController(my second view), and it works perfectly fine when I tap any of my object from the MasterViewController(my first view).

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];  
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

However, when I filter the table list in the masterViewController using searchDisplayController and tap any object from the result, the navigationBar in the detailView doesn't get hidden...

Do I have to do any extra work to hide the navigationBar if I use the searchDisplayController?

for Debug, I set the break point on the line of setNavigationBarHidden:YES, and even if I go to the detailViewController via search result, the application hits the line..


Solution

  • you shuold put [self.navigationController setNavigationBarHidden:YES]; in viewWillLayoutSubviews function.like this:

    - (void) viewWillLayoutSubviews
    {
        [super viewWillLayoutSubviews];
        [self.navigationController setNavigationBarHidden:YES];
    }
    

    it works.