(NSCFType set) – iOS 6中无法识别的选择器

我正在使用伟大的TTTAttributedLabel( https://github.com/mattt/TTTAttributedLabel),它在iOS 5下工作正常.但在iOS 6下,我收到错误:
-[__NSCFType set]: unrecognized selector sent to instance 0x200020e0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',reason: '-  [__NSCFType set]: unrecognized selector sent to instance 0x200020e0'

已经研究了一些问题,似乎已将set消息发送到已经释放的对象.使用调试器,我有po’d 0x200020e0,它似乎是一个CTFontRef.

po 0x200020e0
(int) $0 = 536879328 CTFont <name: .HelveticaNeueUI-Bold,size: 20.000000,matrix: 0x0>
CTFontDescriptor <attributes: <CFBasicHash 0x20001900 [0x3c2a4100]>{type = mutable dict,count = 1,entries =>
1 : <CFString 0x3be2a768 [0x3c2a4100]>{contents = "NSFontNameAttribute"} = <CFString 0x3c292c14 [0x3c2a4100]>{contents = ".HelveticaNeueUI-Bold"}

}

这导致我直截了当地设置了TTTAttributedLabel的代码:

[label setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
    NSRange boldRange = [[mutableAttributedString string] rangeOfString:title options:NSCaseInsensitiveSearch];
    NSRange strikeRange = [[mutableAttributedString string] rangeOfString:@"sit amet" options:NSCaseInsensitiveSearch];


    UIFont *boldSystemFont = [UIFont boldSystemFontOfSize:20];

    CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName,boldSystemFont.pointSize,NULL);

    if (font) {
        [mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)font range:boldRange];
        [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(__bridge id)font range:boldRange];
        CFRelease(font);
    }

    return mutableAttributedString;
}];

如下例所示:

https://github.com/mattt/TTTAttributedLabel

该代码不是ARCized,所以我添加了桥接的cast(见上文).我已经尝试保留了所有的地方,但似乎并没有解决这个问题(似乎是这样),CTFontRef早得到发布(我想 – 其他建议欢迎).

任何关于如何解决这个问题的想法,为什么只会在iOS 6模拟器下面呢?提前致谢.

解决方法

取代:
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName,NULL);

有:

UIFont *font = [UIFont fontWithName:boldSystemFont.fontName size:boldSystemFont.pointSize];

在iOS6中修复了我的问题.未在iOS 5上测试.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...