Question

The code I wrote was working fine until I brought about a BannerView to show ads in the app. To bring the BannerView in all views I used the following code in AppDelegate's didFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if (IS_IPHONE()) {

        UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
        self.viewController = [sb instantiateViewControllerWithIdentifier:@"ViewController"];

    } else {

        UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
        self.viewController = [sb instantiateViewControllerWithIdentifier:@"IpadViewController"];

    }
    self.navigationController=[[UINavigationController alloc]initWithRootViewController:self.viewController];
    self.bannerViewController = [[BannerViewController alloc] initWithContentViewController:self.navigationController];
    self.window.rootViewController = self.bannerViewController;
    [self.window makeKeyAndVisible];

    return YES;
}

But when I used this code a UINavigationItem appears on the top, hiding my actual controls. I want to hide UINavigationItem, not just the buttons. I got the following links on googling.

The first question doesn't have an answer and the answer to the second question doesn't solve my problem, because it is the UINavigationItem itself which I want to hide, not just the buttons. I tried setting the topBar to none in interface builder and tried using the following code:

self.navigationController.toolbarHidden = YES;

In the viewDidLoad but nothing helped a bit. When I comment off the following line from the AppDelegate's didFinishLaunchingWithOptions: method, the view is fine, but then the ad won't show up.

self.window.rootViewController = self.bannerViewController;

What can be done to rectify this?

Was it helpful?

Solution

To hide navigationbar use navigationBarHidden property. Like,

self.navigationController.navigationBarHidden = YES;

for you reference check, UINavigationController Class Reference

if you want to animate your navigationBar while hiding, use

[self.navigationController setNavigationBarHidden:YES animated:YES]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top