“Plain Style unsupported in a Navigation Item” war

2019-02-01 20:14发布

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!

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.

8条回答
三岁会撩人
2楼-- · 2019-02-01 20:28

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

查看更多
不美不萌又怎样
3楼-- · 2019-02-01 20:29

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.

查看更多
冷血范
4楼-- · 2019-02-01 20:32

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.

查看更多
▲ chillily
5楼-- · 2019-02-01 20:34

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

查看更多
成全新的幸福
6楼-- · 2019-02-01 20:40

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.

查看更多
一夜七次
7楼-- · 2019-02-01 20:46

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

查看更多
登录 后发表回答