ios - 不能在顶部放置栏按钮?

标签 ios xcode uistoryboard uibarbuttonitem xcode-storyboard

我只是想建立一个简单的 Storyboard。我有一个 View Controller嵌入 Navigation Controller ,它是应用程序的起始 View 。我添加了整页 Table View和一个 Table View Cell里面。

然后我想加两个Bar Button Items到顶部,但是当我将它们拖入时,这就是问题所在。当我将它拖到顶部栏时,它会在底部创建一个新栏并附加到那里。当我转到文档大纲并手动将其拖到 Navigation Item 下时在View Controller , 然后它工作并转到右上角。

但是我没办法再添加第二个 Bar Button Item到左上角——当我拖进去时,它会到底部,如果我试着把它放在 Navigation Item 下面在文档大纲中和第一个一起,它就不再存在了,好像只有一个Bar Button Item被允许。

我做错了什么?这在过去运作良好。

最佳答案

有时 Storyboard 的日子不好过,xCode 也有错误。然后代码来拯救:

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
showCalendar.frame = CGRectMake( 0, 0, 40, 30 );
[showCalendar setImage:[UIImage imageNamed:@"calendar"] forState:UIControlStateNormal];
[showCalendar addTarget:self action:@selector(METHOD CALL) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

您可以重复此过程以在左侧添加另一个按钮。

关于ios - 不能在顶部放置栏按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25917825/

相关文章:

ios - 如何以编程方式重定向到 iOS 中的电池健康页面?

iphone - 应用内教程

iphone - iPhone 5 上的 UIStoryBoard 如何变化

ios - initWithCoder 在 ios 中显示错误的帧

ios - Storyboard和 ViewController 工厂

ios - 是否可以解码包含未知对象的 NSKeyedArchived 集合

android - zxing条码扫描器在读取第二个二维码时自动对焦问题

ios - 在 Objective-C 中使用 init 方法创建单例的安全方法

iphone - Objective-C 约定 : When to use For and when to use With

ios - XCode 自动交付包含许多文件的构建交付