ios xcode/storyboard:无法将栏按钮拖到顶部的工具栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29435620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
xcode/storyboard: can't drag bar button to toolbar at top
提问by user1904273
I have a view controller that is the detail view of a table. When you click on the row of the table it takes you to the detail view. The detail view is embedded in a navigation controller such that there is a button at the upper left of the navigation bar that sends you back to the table. So far so good.
我有一个视图控制器,它是表的详细视图。当您单击表格的行时,它会将您带到详细信息视图。详细视图嵌入在导航控制器中,因此导航栏左上角有一个按钮,可将您返回到表格。到现在为止还挺好。
I now want to add an edit button to the right side of the navigation bar so that you can edit the detail view. My plan is this will add another view controller modally that lets you edit the details of the item. Standard stuff.
我现在想在导航栏的右侧添加一个编辑按钮,以便您可以编辑详细信息视图。我的计划是这将添加另一个视图控制器,让您编辑项目的详细信息。标准的东西。
However, when I try to drag a bar button item from the list of objects to the navigation bar, it won't take. Instead, when I let go off the mouse button, it leaves the bar button on the tab bar controller at the bottom. (My navigation scheme includes different tabs and for each tab a table, detail view etc.)
但是,当我尝试将栏按钮项从对象列表拖动到导航栏时,它不会。相反,当我松开鼠标按钮时,它会在底部的标签栏控制器上留下条形按钮。(我的导航方案包括不同的选项卡,每个选项卡都有一个表格、详细信息视图等)
Anyone run across this before and can suggest what I'm doing wrong or some sort of workaround to add the bar button item to the right side of the navigation screen. Do I have to add it in code?
任何人之前都遇到过这个问题,并且可以建议我做错了什么或某种解决方法来将栏按钮项添加到导航屏幕的右侧。我必须在代码中添加它吗?
Thanks for any suggestions.
感谢您的任何建议。
回答by Wael Showair
I have got the same problem using Xcode6 and I noticed that UINavigationItem is added automatically for the first ViewController that you embed into NavigationController but for the subsequent ViewControllers, you will have to add it manually as follows:
我在使用 Xcode6 时遇到了同样的问题,我注意到 UINavigationItem 是为您嵌入到 NavigationController 的第一个 ViewController 自动添加的,但对于后续的 ViewControllers,您必须手动添加它,如下所示:
- In the Object library, find Navigation Itemthen drag it to your 2nd ViewController in the storyboard.
- In the Object library, find Bar Button Itemthen drag it the navigation item that you have created in the previous step.
- 在对象库中,找到Navigation Item,然后将其拖到情节提要中的第二个 ViewController。
- 在对象库中,找到 Bar Button Item,然后将其拖动到您在上一步中创建的导航项。
Now you will have your Bar Buttons stuck to the top of your scene.
现在,您将把 Bar Buttons 粘在场景的顶部。
UpdateThe solution still works with XCode 7 but I wanted to add more descriptive photo. Just in case anyone is not really familiar with standard or technical names mentioned above. Notice the red arrows in the right, they refer to step 1, step 2 mentioned above. Also note the hierarchy of views on the left red rectangle.
更新该解决方案仍然适用于 XCode 7,但我想添加更多描述性照片。以防万一有人不是很熟悉上面提到的标准或技术名称。注意右边的红色箭头,它们指的是上面提到的步骤 1、步骤 2。另请注意左侧红色矩形上的视图层次结构。
回答by Baxter Lopez
Nasty trick:
恶作剧:
- Change your segue to push.
- Set the content you need
- Set back to show
- 将您的转场更改为推送。
- 设置你需要的内容
- 设置返回显示
Then the content will be editable and you have a non deprecated style for segue.
然后内容将是可编辑的,并且您有一个非弃用的 segue 样式。
回答by Baxter Lopez
Your storyboard's view controller is likely missing a Navigation Item
. You can drag one from the Object library, and drop it on your view controller.
您的故事板的视图控制器可能缺少Navigation Item
. 您可以从对象库中拖出一个,然后将其放到您的视图控制器上。
You'll then be able to drag and drop bar button items onto the left or right side of the navigation bar.
然后,您就可以将栏按钮项目拖放到导航栏的左侧或右侧。
回答by Jamal N. Ahmad
i Solved it. drag in 'Navigation Item' to your detail view. than you can drag in the Bar Button Item.
我解决了。将“导航项”拖到您的详细信息视图中。比您可以在 Bar Button Item 中拖动。
回答by tallen11
The way that I fixed this issue was, instead of dragging a UINavigationController into the Storyboard and trying to add UIBarButtonItems to that, I dragged in a UITableViewController and then went to
我解决这个问题的方法是,我没有将 UINavigationController 拖入 Storyboard 并尝试向其中添加 UIBarButtonItems,而是拖入 UITableViewController 然后转到
Editor->Embed In->Navigation Controller
编辑器->嵌入->导航控制器
Which gave the same result as before except I could add UIBarButtonItems to both sides of the navigation bar with no issues.
这给出了与以前相同的结果,除了我可以将 UIBarButtonItems 添加到导航栏的两侧而没有问题。
回答by Chetan Kumar
Its actually xcode issue. One trick which worked for me is to add the bar button in the VIEW FILE STRUCTURE ON THE LEFT.Instaed adding on the view directly. Hope it helps you.:)
它实际上是 xcode 问题。对我有用的一个技巧是在 VIEW FILE STRUCTURE ON THE LEFT.Instaed 直接添加视图中添加条形按钮。希望对你有帮助。:)
回答by Hongyang
回答by Hsm
I also had this problem, close and reopen the project worked for me.
我也遇到了这个问题,关闭并重新打开对我有用的项目。
回答by rotarycuff
I believe it's an XCode quirk. I had the same issue. I had to reset Xcode and shift the placement of things on the storyboard to finally get it to go. It's working now.
我相信这是一个 XCode 怪癖。我遇到过同样的问题。我不得不重置 Xcode 并改变故事板上的东西的位置,以最终让它运行。它现在正在工作。
回答by user2174595
I think this is a bug of Xcode. In Xcode 8, change the segue
in storyboard before the tab bar view controller to all its options (show detail
, present
...). Then back to show
. Try to drag bar button items and modify tile. It works for me!
我认为这是Xcode的一个错误。在 Xcode 8 中,segue
将标签栏视图控制器之前的故事板更改为其所有选项(show detail
,present
...)。然后回到show
. 尝试拖动条形按钮项并修改磁贴。这个对我有用!