Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Item not appearing on View Controller

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

like image 256
SRQMarsh Avatar asked Jun 05 '12 03:06

SRQMarsh


People also ask

How do you add navigation to a storyboard?

Go to the Storyboard. Select the View Controller and in The Editor menu select Embed in -> Navigation Controller. Next, drag a Bar Button from the Object Library to the left side of the Navigation Bar and name it "Left Item". Repeat this for the right side and name it "Right Item".

How do I create a navigation bar in Swift?

Start with Navigation ControllerCreate a single view application in Xcode. Add two view controller into your storyboard. Create two different swift files for those view controllers and set identifiers for them. Take a button in each view controller, set constrain for them and customize as you want.


4 Answers

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

like image 159
SRQMarsh Avatar answered Oct 08 '22 07:10

SRQMarsh


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.

like image 29
Tchelow Avatar answered Oct 08 '22 08:10

Tchelow


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

like image 5
Jorge Casariego Avatar answered Oct 08 '22 08:10

Jorge Casariego


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;
like image 1
heckman Avatar answered Oct 08 '22 09:10

heckman