ios “导航项中不支持纯样式”警告与我自定义的条形按钮项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10945859/
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
"Plain Style unsupported in a Navigation Item" warning with my customized Bar Button Item
提问by lu yuan
I drag a Round Rect Button to the position of the right Bar Button Item, and set an image to the Round Rect Button. All works well, except the warning "Plain Style unsupported in a Navigation Item". Even if i select the style of the Bar Button Item to "Bordered", warning still be there. What's the matter with Xcode 4.2? Thanks in advance!
我将一个圆形按钮拖到右侧的条形按钮项目的位置,并将图像设置为圆形按钮。一切正常,除了警告“导航项中不支持普通样式”。即使我将 Bar Button Item 的样式选择为“Bordered”,警告仍然存在。Xcode 4.2 有什么问题?提前致谢!
Ps. I customized many Bar Button Items with Round Rect Button, some times Xcode 4.2 shows only one warning on a Bar Button Item, some times shows warnings on all Bar Button Items.
附言。我使用圆形矩形按钮自定义了许多条形按钮项,有时 Xcode 4.2 只在条形按钮项上显示一个警告,有时在所有条形按钮项上显示警告。
回答by Hunter-Orionntheitroad
I was able to remove these errors by manually editing the storyboard files and find the offending style="plain" entry on Bar Button items in the <navigationItem>
element.
我能够通过手动编辑故事板文件来消除这些错误,并在<navigationItem>
元素中的 Bar Button 项目上找到有问题的 style="plain" 条目。
Changed from:
更改自:
<barButtonItem key="rightBarButtonItem" style="plain" id="juB-DL-F9i">
To:
到:
<barButtonItem key="rightBarButtonItem" id="juB-DL-F9i">
This cleared the warnings... right or wrong.
这清除了警告......对或错。
This may be a stupendous hack and the larger concern is I did not root cause it or remove the invisible bar button items from the overall document. This was after going through all the elements one by one and discovering some navigation bars were empty (without children) and likely occurred with the large amount of copy and paste (cmd+c|v) inheritance and not using duplicate (cmd+d) to build the interface. Although the source cause was not root caused, the symptom was the bar items did not show in the document "outline view" to be fixed. Interface Builder behavior strikes me as nuanced at times and an empty container where there should be something in an outline view is a smell. Well it is to me now. Sometimes deleting the offending node and rebuilding fixes the oddest issues.
这可能是一个了不起的黑客攻击,更大的问题是我没有找到它的根本原因,也没有从整个文档中删除不可见的栏按钮项目。这是在逐一浏览所有元素后发现一些导航栏是空的(没有子项)并且可能发生在大量复制和粘贴(cmd+c|v)继承而不使用重复(cmd+d)来构建界面。虽然根源不是根本原因,但症状是在待修复的文档“大纲视图”中没有显示栏项目。Interface Builder 的行为有时让我觉得很微妙,而在大纲视图中应该有东西的空容器是一种气味。嗯,现在对我来说。有时删除有问题的节点并重建会解决最奇怪的问题。
WARNING: back up your storyboards before you try this... version control is your friend... I take no responsibility when your storyboard is completely hosed and wont compile. All you'll get is an "I told you so!" I learned the hard way a few times, but diligent source control saved me a headache.
警告:在你尝试这个之前备份你的故事板......版本控制是你的朋友......当你的故事板完全被冲洗并且无法编译时,我不承担任何责任。你会得到的只是一句“我早就告诉过你了!” 我学习了几次艰难的方法,但勤奋的源代码控制让我头疼。
EDIT: put brackets in code blocks
编辑:将括号放在代码块中
回答by dstudeba
In case you click on the warning and you don't go to the offending navigation item do the following. (visual representation of Hunter's answer with safer method from comments added in)
如果您单击警告但没有转到违规导航项,请执行以下操作。(从添加的评论中使用更安全的方法直观表示亨特的答案)
In the file browser right click on the storyboard and select Open As Source Code
在文件浏览器中右键单击情节提要并选择 Open As Source Code
In the source code page search for "plain", and find the one attached to a Navigation Item.
在源代码页面中搜索“plain”,并找到附加到导航项的那个。
To get the name of the View, put "scene" in the search bar and click the back search arrow to search for the first instance on that tag abovethe navigationItem
要获取视图的名称,请将“场景”放在搜索栏中,然后单击后退搜索箭头以搜索该标签上方的第一个实例navigationItem
Here is the name of your Scene, you can now change your Storyboard view back to Interface Builder - Storyboard
with the right click method described above, and then go to select the Scene in the scene menu, and the Bar Item inside it.
这是场景的名称,您现在可以Interface Builder - Storyboard
使用上面描述的右键单击方法将Storyboard 视图改回,然后在场景菜单中选择 Scene 和其中的 Bar Item。
Go to the Attributes inspector and change the style from Plain
to Bordered
转到属性检查器并将样式从 更改Plain
为Bordered
回答by MarkAurelius
I stopped the warning about Plain Style by poking around in the Document Outline. That was showing my Navigation Item, and within that 2 Bar Button Items, and within each of those a Button. The offending setting was on the Bar Button Item. In its attributes inspector I changed Style from Plain to Done, and the warning went away. Note: I am using XCode 5.
我通过查看文档大纲来停止有关普通样式的警告。那是显示我的导航项,在 2 个条形按钮项中,在每个按钮项中。有问题的设置在 Bar Button Item 上。在它的属性检查器中,我将 Style 从 Plain 更改为 Done,警告消失了。注意:我使用的是 XCode 5。
回答by Recycled Steel
If you are using storyboard then click the warning and it should take you to the offending navigation item (I had two for the problem, one took me there the other did not) - change the style and clean the project.
如果您正在使用故事板,则单击警告,它应该带您到有问题的导航项(我有两个问题,一个带我去那里另一个没有) - 更改样式并清理项目。
回答by Mat
backBarButtonItem
leftBarButtonItem
and rightBarButtonItem
are UINavigationItem
objects. There is no style
property in UINavigationItem
so this is the reason of the warning. You should set the barButtons programatically:
backBarButtonItem
leftBarButtonItem
并且rightBarButtonItem
是UINavigationItem
对象。没有style
财产,UINavigationItem
所以这是警告的原因。您应该以编程方式设置 barButtons:
iOS 4: ?
iOS 4:?
UIButton *bt=[UIButton buttonWithType:UIButtonTypeRoundedRect];
?[bt setFrame:YourFrame];
//[bt setImage:[UIImage imageNamed:@"backBT"] forState:UIControlStateNormal];
?[bt addTarget:self action:@selector(popViewController:) forControlEvents:UIControlEventTouchUpInside];
?UIBarButtonItem *leftButton=[[UIBarButtonItem alloc] initWithCustomView:bt];
?self.navigationItem.leftBarButtonItem=leftButton;
For iOS 5+:
对于 iOS 5+:
Read the "Customizing Appearance" section of UIBarButtonItem reference.
阅读UIBarButtonItem 参考的“自定义外观”部分。
回答by iOSDev
In the navigation bar try using UIBarButtonItem instead of Round rect button and set an Image for it .
在导航栏中尝试使用 UIBarButtonItem 而不是 Round rect button 并为其设置 Image 。
回答by user462990
In my case it was an image of a back arrow, which was set to "Plain".
在我的例子中,它是一个后退箭头的图像,它被设置为“普通”。
The error message appears to refer to all the items in the navigation bar.
错误消息似乎是指导航栏中的所有项目。
回答by Sethmr
After you are sure that you have all your bar buttons in the storyboard set to anything but plain, make sure you do a git commit and delete derived data. I spent forever trying to figure out why the problem wasn't fixing itself, and deleting the derived data folder fixed it for me.
在您确定将故事板中的所有条形按钮设置为非普通样式后,请确保执行 git commit 并删除派生数据。我花了很长时间试图弄清楚为什么问题没有自行修复,并删除派生数据文件夹为我修复了它。