我只是想建立一个简单的 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/