Finding cause of “Automatic Preferred Max Layout W

2019-03-18 08:20发布

I know the reason of this warning and how to solve it: to give a preffered width to the label.

The problem is that, when I click that warning, I don't see any label/view/viewcontroller selected. The storyboard opens and that's it. There are many view controllers with many views in my storyboard. How can I find out which label is causing the problem without iterating through all the view controllers manually? When I click the warning, I expect it to take me to the view causing the warning, but it just opens the storyboard.

8条回答
闹够了就滚
2楼-- · 2019-03-18 08:34

As said in that post, you can also use this regex <label(?!.*preferredMaxLayoutWidth) in storyboard source to find all labels that do not have a preferredMaxLayoutWidth setted. Then correct it.

查看更多
迷人小祖宗
3楼-- · 2019-03-18 08:34

Is that the warning from a collection view? If so I'd guess it's a cell and a label with number of lines set to zero.

查看更多
Emotional °昔
4楼-- · 2019-03-18 08:35

just remove number of line from label and set it programmatically

[label setNumberOfLines:2];
查看更多
Viruses.
5楼-- · 2019-03-18 08:42

I had the same problem in an existing project developed in 7.1 without autolayouts. Once I migrated the app to iOS8 and changed in the project file the version to 8.0, for some reason I got that warning in the Xib's where I used UILabel's with multiple lines.

in order to correct the problem, select the file inspector for the Xib and check the version it Builds for, in my case it was still for iOS7

enter image description here

you should change the Build for to the relevant version

enter image description here

and the warning will disappear as it did in my case :-)

查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-03-18 08:45

Here is one way to find the specific label that is causing this warning:

  1. Right click on the warning and choose "Reveal in Log"
  2. The warning in the log will be highlighted. Copy the interface builder object ID for this label (it looks like xxx-xx-xxx).
  3. Paste this in the Find Navigator. When you click on this result it will open the interface builder with the offending label selected.
查看更多
淡お忘
7楼-- · 2019-03-18 08:50

Answer of @Don Eichenseer is great. But for those who want to solve it: I've got the same problem before. The issue was because of a UILabel which its Lines property (in Attributes inspector) was more than 1. When you have found the related UILabel, set it Lines to 1.

查看更多
登录 后发表回答