xcode 查找“自动首选最大布局宽度在 8.0 之前的 iOS 版本上不可用”的原因

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26920464/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:10:35  来源:igfitidea点击:

Finding cause of "Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0"

xcodeinterface-builderxcode6xcode6.1

提问by Can Poyrazo?lu

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.

问题是,当我单击该警告时,我没有看到任何标签/视图/视图控制器被选中。故事板打开,就是这样。在我的故事板中有很多视图控制器。如何在不手动遍历所有视图控制器的情况下找出导致问题的标签?当我单击警告时,我希望它带我到导致警告的视图,但它只是打开故事板。

回答by Don Eichenseer

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.
  1. 右键单击警告并选择“在日志中显示”
  2. 日志中的警告将突出显示。复制此标签的接口构建器对象 ID(看起来像 xxx-xx-xxx)。
  3. 将其粘贴到 Find Navigator 中。当您单击此结果时,它将打开界面构建器,并选择有问题的标签。

回答by Tom Howard

Running XCODE 6.1, I found the easiest way to do find the error was through the Report Navigator.

运行 XCODE 6.1,我发现查找错误的最简单方法是通过 Report Navigator。

  1. View-> Navigators-> Show Report Navigatoror simply press ?-8
  2. Click on the build in the left pane.
  3. Click the details icon next to the warning.
  1. View-> Navigators->Show Report Navigator或只需按?-8
  2. 单击左窗格中的构建。
  3. 单击警告旁边的详细信息图标。

enter image description here

在此处输入图片说明

  1. Find the object id in the warning description.
  1. 在警告描述中找到对象 ID。

enter image description here

在此处输入图片说明

  1. Go to the file and search ?-ffor the object id.
  1. 转到文件并搜索?-f对象 ID。

enter image description here

在此处输入图片说明

  1. Fix the issue. Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
  1. 解决问题。自动首选最大布局宽度在 8.0 之前的 iOS 版本上不可用

回答by Fadi Abuzant

just remove number of line from label and set it programmatically

只需从标签中删除行数并以编程方式设置

[label setNumberOfLines:2];

回答by Romain TAILLANDIER

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.

该帖子所述,您还可以在故事板源中使用此正则表达式 <label(?!.*preferredMaxLayoutWidth)来查找所有没有设置 preferredMaxLayoutWidth 的标签。然后改正。

回答by Majid

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 UILabelwhich its Linesproperty (in Attributes inspector) was more than 1. When you have found the related UILabel, set it Lines to 1.

@Don Eichenseer 的回答很棒。但是对于那些想要解决它的人:我以前也遇到过同样的问题。问题是因为UILabel它的Lines属性(在属性检查器中)大于1. 找到相关的后UILabel,将其设置为 Lines 1

回答by Henry T Kirk

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.

这是来自集合视图的警告吗?如果是这样,我猜它是一个单元格和一个标签,行数设置为零。

回答by Gutty1

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.

我在没有自动布局的 7.1 中开发的现有项目中遇到了同样的问题。一旦我将应用程序迁移到 iOS8 并在项目文件中将版本更改为 8.0,出于某种原因,我在 Xib 中收到了该警告,我在其中使用了多行 UILabel。

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

为了更正问题,选择 Xib 的文件检查器并检查它构建的版本,在我的情况下它仍然适用于 iOS7

enter image description here

在此处输入图片说明

you should change the Build for to the relevant version

您应该将 Build for 更改为相关版本

enter image description here

在此处输入图片说明

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

并且警告将像我的情况一样消失:-)

回答by samthui7

I must switch to XCode 6.2 --> click on warning icon at top right of the main XCode area --> choose the warning --> it shows exactly the item that cause the warning. enter image description here

我必须切换到 XCode 6.2 --> 单击主 XCode 区域右上角的警告图标 --> 选择警告 --> 它准确显示导致警告的项目。 在此处输入图片说明