[翻译]  Navigation Item not appearing on View Controller

[CHINESE]  导航项目未出现在View Controller上


I apologize I am new to iphone programming.

我很抱歉我是iphone编程的新手。

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.

我创建了一个Master-Detail Iphone应用程序(因此导航控制器附带了该项目)。我通过masterviewcontroller上的UIBarButtonItem创建了一个新的视图控制器。然而,与detailviewcontroller(项目附带)不同,我似乎无法在视图上显示导航项(或导航栏?),即使它出现在我的故事板的场景列表中。

Heres some code and a screenshot:

下面是一些代码和截图:

In my masterviewcontroller.m viewdidload() function

在我的masterviewcontroller.m viewdidload()函数中

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

in my masterviewcontroller.m

在我的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)

我尝试在我创建的新viewcontroller.m类的viewDidLoad函数中为navigationitem添加标题(在此链接中提到但它不起作用)

- (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.

所以我的问题是为什么它现在出现了,我如何得到它?我想要一个后台按钮,就像我的详细视图控制器,它与master-detail项目一起提供。

EDIT#1

编辑#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.

我已经添加了一个检查导航控制器是否为零并且它不是nil(if语句从未输入)我也尝试将导航项更改为后退并删除,但没有一个工作。

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

5 个解决方案

#1


12  

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

由于我的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

将场景从主视图控制器移动到设置视图控制器的segue设置为“模态”。它必须设置为“推”。这是从实用程序窗格上的故事板完成的

#2


6  

You have to change your Segue Style by doing this:

你必须通过这样做来改变你的Segue Style:

  • Select the Segue in your Storyboard;
  • 在故事板中选择Segue;
  • Go to the Attributes inspector (on the right pane tabs);
  • 转到“属性”检查器(在右窗格选项卡上);
  • Change the Style attribute to Push.
  • 将Style属性更改为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.

它将使屏幕从右向左滚动,导航栏将显示为滑动。使用Modal,屏幕从屏幕的底部到顶部,不会出现导航栏。

#3


4  

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

#4


1  

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

您已验证viewDidLoad方法中列出的导航控制器是否为零?

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!

假设你正确地拥有一个非零的self.navigationItem,你似乎错误地将self.navigationItem.leftBarButtonItem设置为editButtonItem,而是尝试将它们全部一起删除!

If removing it does not solve the problem try:

如果删除它不能解决问题,请尝试:

self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;

#5


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];

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号