ios - scaledValueForValue : called on a font that doesn't have a text style set

标签 ios objective-c xcode ios8 xcode6

我目前正在使用 Xcode 6 预发行版(不是测试版)和 OS X 10.10 Yosemite beta 7 上的模拟器。我正在尝试构建一个在 xcode 6 中开发的项目,但每当我打开某个 View Controller 时应用程序就会崩溃.这个 View Controller 实际上没有代码(它是一个空的、静态的、具有几个默认单元格和标签的表格 View Controller )。

给出的错误是:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:  
'scaledValueForValue: called on a font that doesn't have a text style set'

在我遇到这个断言失败之前:

*** Assertion failure in -[UICTFont _scaledValueForValue:],         
/SourceCache/UIFoundation_Sim/UIFoundation-371/UIFoundation/iOS/UIFont.m:496

我真的不知道发生了什么,我尝试在 VC 中设置断点,但错误发生在调用 viewDidLoad 方法之后(因此在我的所有代码都执行之后)。

有什么想法吗?我项目中所有字体的字体都是“Baskerville”,我已经尝试更改它,但它不会影响崩溃。

哦,如果我使用 Xcode 5,它就可以正常工作。

9/24 更新:所以我仍然无法弄清楚这一点。我尝试使用 fontWithDescriptor 方法,但它仍然崩溃。有趣的是,我有很多使用自定义字体的页面,而且大多数都可以正常工作,但是当我访问它们时,有两个 VC 会立即崩溃……其中一个甚至没有任何自定义字体。我非常感谢您的所有反馈,但有人有其他想法/修复吗?我用的是Xcode的官方版本,还是不行。

最佳答案

此问题已在 iOS 8.1 中修复。

我没有花时间构建自定义页眉/页脚 View ,只是不将自定义字体应用于运行 iOS 8.0 的设备。无论如何,大多数人可能已经更新到 iOS 8.1。

我为此使用以下代码:

NSOperatingSystemVersion iOS_8_1 = (NSOperatingSystemVersion){8, 1, 0};

if (![[NSProcessInfo processInfo] respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)]
    || [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:iOS_8_1]) {
    header.textLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:header.textLabel.font.pointSize];
}

如果设备运行的 iOS 版本低于 8,则第一个语句为真(因为在 iOS 8.0 中引入了 isOperatingSystemAtLeastVersion:)。如果设备运行 iOS 8.1 或更高版本,则第二个语句为真。因此,对于这两种说法,我们只排除了运行 iOS 8.0 的设备。

关于ios - scaledValueForValue : called on a font that doesn't have a text style set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25773661/

相关文章:

ios - 当前日期仅以 nsdate 格式显示 "mm/dd/yy "不会在 swift 中转换为 nsstring

ios - 从 Storyboard 加载 Collection View Cell(而不是从带有 registerNib 的 nib)

ios - UIModalTransitionStylePartialCurl 使我的应用程序崩溃

ios - 如何使用图像的像素数据将图像旋转 90 度?

iphone - NSCachesDirectory 不是我的文件系统中的目录

objective-c - 适用于 Mac 的类似 ShareKit 的框架

objective-c - UIDocumentInteractionController与presentOpenInMenuFromBarButtonItem:方法一起崩溃

ios - 从过滤后的搜索结果中快速删除条目

ios - iOS 框架的代码签名

ios - UILabel 文字一一淡出