Search code examples
iphoneobjective-cios7

UINavigationbar Prompt overlaps the screen content


ran into a weird issue. If I set the prompt on the navigation controller, navbar overlaps the content of the screen. What is the proper way of dealing with this?

    -(id)initwithsomestuff:(stuff)
    {
...
    self.title = @"My Title";
    self.navigationItem.prompt = "@Prompt";
...
    }

When this view controller is pushed on, it first appears, then it resizes it's navigation bar to show the prompt in it. But that has a nasty side effect of not resizing the screen content below and covers a good amount of stuff I actually need on the screen.

What's a preferred way of handling this issue? Layout is in xib if that helps.


Solution

  • One problem you have is your init function needs to call super. Following your example, it would look like this:

    - (id)initWithSomeStuff:(id)stuff
    {
        self = [super init];
        if (self) {
            self.title = @"My Title";
            self.prompt = @"Prompt";
        }
        return self;
    }
    

    Next, are you developing against iOS 7? It is intended behavior to cover the content with the navigation bar by default. If you want to suppress this behavior, perform the following on your view controller:

    self.edgesForExtendedLayout = UIRectEdgeNone; 
    self.extendedLayoutIncludesOpaqueBars = NO; 
    

    You can also set these on the View Controller in the Story board. They are shown on the Properties tab, under Extend Edges.