简体   繁体   中英

ios noob: why doesn't my view controller show the title that I have assigned in the inspector

I am learning iOS by following O'Reilly Headfirst iPhone Development 2e.

I am trying to assign the title to a viewcontroller so that it looks like this: 在此处输入图片说明

But even when I set the title (as shown in the picture below) the title bar is still blank when the app runs in the simulator. I am sure I am missing something really obvious, but this is all really new so don't know what box to check/setting to configure in the IDE. I'm stuck. What should I click?

在此处输入图片说明

You have to select the navigation bar and define a title. You're defining the View Controller title, it's not the same thing.

What you're doing is nothing like what the book is telling you to do. It tells you to set the view controller in a nib; you're using a storyboard. It tells you to set the title of the view controller's navigation item; you're setting it on the view controller itself. In other words you're doing something different from what the book is saying to do, and then you're complaining that something different results.

You can set in this way also, other than set it in the interface builder.

if you gonna define a title for uinavigation bar use self.navigationItem.title = @"your title"; <-- in viewDidLoad

if it's view controller title use:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        // self.title = @"your title";
    }
    return self;
}

if you are new to ios, I recommend not to use storyboard.

Not an answer, per se.

I did this tutorial too, and find the book helpful. Start over and use nibs. Choose the Master-Detail template. However, if you want to keep using storyboards, follow this tutorial that tells you how to create a tableview with a drill-down: http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

It will tell you how to set the title. I suspect that you've created your navigation bar or tableview incorrectly if you can't click on the Navigation Item and see where to set 'Title' in the attributes window.

Make sure you have your navigation bar selected, as far as I can see now you have selected your viewcontroller and not your navigation bar. You can also double click on the navigation bar to set a title, it will appear in your attributes inspector as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM