scaledValueForValue:调用没有文本样式集的字体

Jos*_*osh 38 xcode objective-c ios xcode6 ios8

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

给出的错误是:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:  
'scaledValueForValue: called on a font that doesn't have a text style set'
Run Code Online (Sandbox Code Playgroud)

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

*** Assertion failure in -[UICTFont _scaledValueForValue:],         
/SourceCache/UIFoundation_Sim/UIFoundation-371/UIFoundation/iOS/UIFont.m:496
Run Code Online (Sandbox Code Playgroud)

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

有任何想法吗?我项目中所有内容的字体都是'Baskerville',我尝试过改变它,但它不会影响崩溃.

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

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

Jon*_*han 23

此问题已在iOS 8.1中得到修复.

我没有花时间构建自定义页眉/页脚视图,而是将自定义字体应用于运行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];
}
Run Code Online (Sandbox Code Playgroud)

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