(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上测试.

以上是来客网为你收集整理的(NSCFType set) – iOS 6中无法识别的选择器全部内容,希望文章能够帮你解决(NSCFType set) – iOS 6中无法识别的选择器所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。