Navigation Item not appearing on View Controller
Asked Answered
R

7

14

I apologize I am new to iphone programming.

I have created a Master-Detail Iphone application (so Navigation Controller came with the project). I segue to a new view controller I created through a UIBarButtonItem on the masterviewcontroller. However unlike the detailviewcontroller (that came with the project) I can not seem to get the navigationitem (or navigationbar?) to display on the view even though it appears in the scene list of my storyboard.

Heres some code and a screenshot:

In my masterviewcontroller.m viewdidload() function

UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:normal target:self action:@selector(goToSettings:)];
self.navigationItem.leftBarButtonItem = settingsButton;

in my masterviewcontroller.m

- (IBAction)goToSettings:(id)sender{    
    [self performSegueWithIdentifier:@"SettingsSegue" sender:self];
}

I tried adding a title to the navigationitem during the viewDidLoad function of the new viewcontroller.m class i created (mentioned in this Link but it didn't work)

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"Settings";
    self.navigationItem.leftBarButtonItem = self.editButtonItem;
}

But it still shows up in my storyboard ( it shows up in the list under the scene but not in the display of the view)

So my question is why is it now showing up and how do I get it to? I want a back button like my detail view controller that came with the master-detail project.

EDIT#1

I have added a check for whether navigation controller is nil and it is not nil (the if statement is never entered) I also tried changing the navigation item to back and removing and none has worked.

if(self.navigationItem == nil)
{
    [ self.navigationItem init];
}
self.navigationItem.title = @"Settings";
self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;

Now that I have enough reputation to show an image I can show that the navigation item shows up in the list but doesnt show up on the view

enter image description here

Ridglee answered 5/6, 2012 at 3:1 Comment(1)
The if statement here is never entered, because the docs say that self.navigationItem is created on the fly.Soissons
R
15

The Navigation item did not show up because of the "style" of my segue.

The segue that moved the scene from the master view controller to the settings view controller was set to 'modal'. It has to be set to 'push'. This is done from the storyboard on the utilities pane

Ridglee answered 5/6, 2012 at 23:47 Comment(0)
D
6

You have to change your Segue Style by doing this:

  • Select the Segue in your Storyboard;
  • Go to the Attributes inspector (on the right pane tabs);
  • Change the Style attribute to Push.

It will make the screen roll from right to left and the Navigation bar will appear sliding. With Modal, the screen come from bottom to the top of the screen and it will not let the Navigation bar appears.

Deck answered 23/11, 2012 at 18:29 Comment(0)
S
5

The problem in my case was that the Navigation controller wasn't the "initial View Controller"

So I had to do this

enter image description here

Sycophant answered 27/10, 2014 at 18:31 Comment(0)
U
1

You have verified that your navigation controller listed in the viewDidLoad method is not nil?

Assuming that you do correctly have a self.navigationItem that is non-nil, it appears that you are incorrectly setting your self.navigationItem.leftBarButtonItem to an editButtonItem, instead try removing this all together!

If removing it does not solve the problem try:

self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;
Unchaste answered 5/6, 2012 at 3:29 Comment(0)
O
0

Please check if your view controller is the root view controller of the navigation controller. You cant directly present a view controller as a modal view controller. You have to make your view controller as the root view controller of a navigation controller and then present your navigation controller as the modal view controller.

// Create the root view controller for the navigation controller
// The new view controller configures a Cancel and Done button for the
// navigation bar.
YourViewController *addController = [[YourViewController alloc]
                   init];

// Configure the YourViewController.

// Create the navigation controller and present it.
UINavigationController *navigationController = [[UINavigationController alloc]
                         initWithRootViewController:addController];
[self presentViewController:navigationController animated:YES completion: nil];
Objection answered 15/9, 2014 at 18:7 Comment(0)
P
0

You need to have a Navigation Controller and a View Controller.

"The navigation controller manages the navigation bar at the top of the interface and an optional toolbar at the bottom of the interface. The navigation bar is always present and is managed by the navigation controller itself, which updates the navigation bar using the content provided by its child view controllers. When the isToolbarHidden property is false, the navigation controller similarly updates the toolbar with contents provided by the topmost view controller." https://developer.apple.com/documentation/uikit/uinavigationcontroller

enter image description here

Pandorapandour answered 20/4, 2020 at 8:17 Comment(0)
W
0

The Navigation Item also appears in the View Controller Scene you can look for it there and edit it too

Wrac answered 11/7, 2020 at 1:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.