leftbarbuttonitem没有显示在导航栏中 [英] leftbarbuttonitem does not show up in the navigation bar

查看:287
本文介绍了leftbarbuttonitem没有显示在导航栏中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发iOS应用,并且在将图片用作导航栏中的左栏按钮项时遇到了问题。我已尝试通过以下方式进行此操作:

I've been developing an iOS app and have been having issues with using an image as the left bar button item in the navigation bar. I have attempted this in the following ways:

UIImage *backButtonImage = [UIImage imageNamed:@"backbuttonCB"];
CGRect buttonFrame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
UIButton *backButton = [[UIButton alloc] initWithFrame:buttonFrame];
[backButton setImage:backButtonImage forState:UIControlStateNormal];
UIBarButtonItem *backBarButtonItem= [[UIBarButtonItem alloc] initWithCustomView: backButton];
self.navigationItem.leftBarButtonItem = backBarButtonItem;

运行应用程序时,似乎从未显示bar按钮。

The bar button never seems to display while running the app.

然后我尝试按以下方法尝试另一种方法。

I then proceeded to try this other method as follows.

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backbuttonCB"] style:UIBarButtonItemStylePlain target:nil action:@selector(methodname)];

此方法实际上有效。但是,显示的图像为蓝色,看起来不像预期的那样。更改此图像的色调颜色无济于事。

This method actually worked. However, the image displayed was tinted blue and did not look like it was meant to. Changing the tint colour of this image did not help.

有什么办法可以解决这个问题吗?

Any idea how I can solve this problem?

编辑:更多信息,如果有帮助的话。
这是导航堆栈中的第一个视图。导航堆栈以模态显示,即,有一个先前的视图控制器,并且在先前的视图控制器和导航控制器之间有一个模式选择。这是导航堆栈中的第一个视图。

More information, if it helps. This is the first view in the navigation stack. The navigation stack is displayed modally i.e. there is a previous view controller and there is a modal segue between the previous view controller and the navigation controller. This is the first view in the navigation stack.

编辑:问题已解决。
我认为这是xcode中的错误,因为当我重新启动xcode并使用实际设备而不是仿真器对其进行测试时,它可以正常工作。但是,在仿真器上似乎仍然无法运行。

THE PROBLEM IS FIXED. I think it was a bug in xcode because when I restarted xcode and tested it with an actual device instead of the emulator, it worked fine. However, still doesn't seem to work on an emulator.

推荐答案

尝试以这种方式设置leftBarButtonItem。

Try setting your leftBarButtonItem this way. While presenting modally it doesn't shows up.

self.navigationController?.navigationBar.topItem.leftBarButtonItem =

这篇关于leftbarbuttonitem没有显示在导航栏中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆