94

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?

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.

starball
  • 20,030
  • 7
  • 43
  • 238
lu yuan
  • 7,207
  • 9
  • 44
  • 78
  • 1
    I wrote a blog post about this: http://blog.mosheberman.com/fixing-plain-style-unsupported-in-a-navigation-item-in-xcode-7/ – Moshe Apr 05 '16 at 15:46
  • Don't add buttons, add bar button items. This was my mistake. –  Jan 03 '19 at 22:18

8 Answers8

141

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

Hunter-Orionnoir
  • 2,015
  • 1
  • 18
  • 23
  • 27
    select the barbuttonitem in interface builder, open attributes panel on the right, and changing the bar button item's style to "Bordered" applied the same diff to the storyboard file. so this should be safe. – mash Apr 10 '15 at 15:08
  • Thanks for that advice @mash, the way I did it was horribly wrought with potential pain and suffering. – Hunter-Orionnoir Aug 04 '15 at 21:52
  • @SpaceDog2 Thanks for the heads up. I haven't upgraded yet, so I can't add any confirmation to that. I would real careful with this method anyway. I know its helped a lot of folks so far. In time we will see if it discontinues to help. – Hunter-Orionnoir Oct 18 '15 at 07:50
  • 5
    This solution worked perfectly for me in Xcode 7.1. Also, instead of directly editing the source code, you can change this in the storyboard itself (switching the style from Plain to Bordered), and that has the exact same result as just manually deleting `style="plain"` from the storyboard source code. So, to me this suggestion from Hunter seems legit. – Erik van der Neut Nov 13 '15 at 02:56
  • Check out dstudeba's answer too, I didn't even know what he described was possible. might save everyone some pain and suffering from hand editing the file. Source control is your friends, be safe everyone. ;) – Hunter-Orionnoir Nov 15 '15 at 07:06
  • Thanks! Did it through IB but the result on the file was the same. – Felipe Jun 09 '17 at 00:59
34

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

dstudeba
  • 8,878
  • 3
  • 32
  • 41
13

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.

MarkAurelius
  • 1,203
  • 1
  • 14
  • 27
8

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

Recycled Steel
  • 2,272
  • 3
  • 30
  • 35
  • In this problem above it did not actually take me anywhere. I think that is the sticking point of this particular issue, the item was missing from the navigator altogether, but dstudeba's answer has an interesting approach, be curious if opening the storyboard differently helps people. – Hunter-Orionnoir Nov 15 '15 at 07:09
  • This is the most appropriate answer. I've changed the style to Bordered. – Andrej Jul 08 '16 at 13:06
6

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.

Mat
  • 7,613
  • 4
  • 40
  • 56
  • 3
    I have an inherited project with a lot of view controllers & buttons. I can't seem to coax XCode into telling me which button is causing the warning. Any hints? Thanks! – Olie Sep 23 '13 at 19:46
  • Maybe run through your view controllers and "find" UIBarButtonItenStyle. That's usually where the property is wrongly set – TimWhiting Mar 12 '15 at 19:32
1

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

Prabha
  • 424
  • 1
  • 4
  • 11
1

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.

user462990
  • 5,472
  • 3
  • 33
  • 35
0

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.

Sethmr
  • 3,046
  • 1
  • 24
  • 42