“导航项中不支持普通样式”的警告

我拖动一个圆形按钮到右边的酒吧按钮项目的位置,并设置一个图像的圆形按钮。除了警告“导航项中不支持普通样式”之外,其他都可以正常工作。即使我选择的酒吧按钮项目的样式为“镶边”,警告仍然存在。Xcode 4.2怎么了?先谢谢你!

P.我定制了许多圆形按钮的条形按钮项目,有时 Xcode 4.2在条形按钮项目上只显示一个警告,有时在所有条形按钮项目上显示警告。

42473 次浏览

In the navigation bar try using UIBarButtonItem instead of Round rect button and set an Image for it .

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:

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+:

Read the "Customizing Appearance" section of UIBarButtonItem reference.

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.

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.

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.

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

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.

Bar Button Style set to plain

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

enter image description here

In the source code page search for "plain", and find the one attached to a Navigation Item.

enter image description here

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 above the navigationItem

enter image description here

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.

enter image description here

Go to the Attributes inspector and change the style from Plain to Bordered

enter image description here

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.

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.