3

This one doesn't make any sense to me. My app crashes with the following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType screenFontWithRenderingMode:]: unrecognized selector sent to instance 0x209bb200'

This is an iOS app. From what I can see, screenFontWithRenderingMode is an NSFont method for Mac OS X, not iOS. So how can this error even be occurring?

I am building the app with the newly released Xcode 5. The app will support iOS version 6.1 and 7.0 (and higher). This error ONLY occurs when running the app on a 6.1 device (and simulator).

EDIT:

I wasn't able to produce the crash log by running the app in debug mode. By creating an Ad Hoc build I was able to load the app, run it, crash, and retrieve the crash log:

0   CoreFoundation                  0x3220a29e __exceptionPreprocess + 158
1   libobjc.A.dylib                 0x3a06e97a objc_exception_throw + 26
2   CoreFoundation                  0x3220de02 -[NSObject(NSObject) doesNotRecognizeSelector:] + 166
3   CoreFoundation                  0x3220c52c ___forwarding___ + 388
4   CoreFoundation                  0x32163f64 __forwarding_prep_0___ + 20
5   UIFoundation                    0x37da15c8 +[NSStringDrawingTextStorage _fastDrawString:attributes:length:inRect:graphicsContext:baselineRendering:usesFontLeading:usesScreenFont:typesetterBehavior:paragraphStyle:lineBreakMode:boundingRect:padding:scrollable:baselineOffset:] + 344
6   UIFoundation                    0x37da0184 -[NSAttributedString(NSExtendedStringDrawing) _doBoundingRectWithSize:options:context:baselineOffset:] + 676
7   UIFoundation                    0x37d9fc8c -[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] + 2492

I was able to track down the offending line:

CGRect rect = [[MLFeedCell attributedBodyForItem:item].attributedString boundingRectWithSize:CGSizeMake(labelWidth, 10000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];

I'm not sure what's wrong with this call.

4

1 回答 1

3

The error is because you are trying to use:

[NSString boundingRectWithSize:options:attributes:context:]

That method was added in IOS 7.0 in the NSStringDrawing.h category.

source:

于 2013-11-22T18:22:13.017 回答