scaledValueForValue: called on a font that doesn&#

2019-01-31 16:01发布

I am currently using the Xcode 6 pre release (not beta) and the simulator on OS X 10.10 Yosemite beta 7. I am trying to build a project developed in xcode 6, but the app crashes whenever I open a certain view controller. This view controller literally has no code in it (it is an empty, static, table view controller that has a couple of default cells and labels).

The error given is:

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

And right before I am given this assertion failure:

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

I seriously have no idea what is going on, I tried setting breakpoints in the VC but the error happens after the viewDidLoad method is called (and thus after all my code is executed).

Any Ideas? The fonts for everything in my project is 'Baskerville' and I have tried changing that but it does not affect the crash.

Oh, and it works fine if I use Xcode 5.

Update 9/24: So I am still unable to figure this out. I tried using the fontWithDescriptor method, but it still crashes. The funny thing is, I have plenty of pages that use custom fonts and most of them work fine, but there are two VCs that crash immediately when I go to them... one of them doesn't even have any custom fonts. I really appreciate all of your feedback, but does anyone have any other ideas/fixes? I am using the official release of Xcode and it still doesn't work.

8条回答
孤傲高冷的网名
2楼-- · 2019-01-31 16:33

Take a look at: http://openradar.io/17623734

Unfortunately at this early stages of xCode 6 I can only offer a workaround for the crash.

Replace this line:

[header.textLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:17]];

for this:

header.textLabel.font = [UIFont fontWithDescriptor:[UIFontDescriptor fontDescriptorWithFontAttributes:@{@"NSCTFontUIUsageAttribute" : UIFontTextStyleBody,
                                                                                                        @"NSFontNameAttribute" : @"HelveticaNeue-Italic"}] size:17.0];
查看更多
时光不老,我们不散
3楼-- · 2019-01-31 16:34

This problem is still present in iOS 8.0.2 but seems to be fixed in 8.1.

My workaround was to set the custom font only if iOS is greater than 8.0.2:

#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

...

if (SYSTEM_VERSION_GREATER_THAN(@"8.0.2")) {
    [[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setFont:[UIFont fontWithName:@"Helvetica" size:14.0]];
}
查看更多
登录 后发表回答