简体   繁体   English

ios noob:为什么我的视图控制器不显示我在检查器中分配的标题

[英]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. 我正在按照O'Reilly Headfirst iPhone Development 2e学习iOS。

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. 我敢肯定我确实遗漏了一些明显的东西,但这都是真的,所以不知道要在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"; 如果您要为导航栏定义标题,请使用self.navigationItem.title = @“您的标题”; <-- in viewDidLoad <-在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. 如果您不熟悉ios,建议不要使用情节提要。

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 但是,如果您想继续使用情节提要,请遵循本教程,该教程告诉您如何使用明细创建表格视图: 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. 确保选择了导航栏,据我现在所看到的,您选择的是ViewController,而不是导航栏。 You can also double click on the navigation bar to set a title, it will appear in your attributes inspector as well. 您也可以双击导航栏以设置标题,该标题也会显示在属性检查器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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