(NSCFType集合)-iOS 6中无法识别的选择器

(NSCFType集合)-iOS 6中无法识别的选择器,ios,xcode,ios6,core-text,ctfontref,Ios,Xcode,Ios6,Core Text,Ctfontref,我使用的是很棒的tttatAttributedLabel(),它在iOS 5下运行良好。但是,在iOS 6下,我得到一个错误: -[__NSCFType set]: unrecognized selector sent to instance 0x200020e0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [__NSCFType set]: unrecognize

我使用的是很棒的tttatAttributedLabel(),它在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 0x200000e0,它似乎是一个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"}
与此处的示例用法相同:

该代码没有被ARCified,因此我添加了桥接转换(见上文)。我已经尝试过到处保留,但这似乎并不能解决CTFontRef发布太早的问题(我认为——欢迎其他建议)


关于如何解决这个问题,以及为什么只有在iOS 6模拟器下才会出现这个问题,有什么想法吗?提前感谢。

我在使用UILabel myLabel时遇到了相同的错误, 并执行myLabel.attributedText=NSMutableAttributedString

试一试

宣布:

@property(非原子,强)iboAttributedLabel*myLabel

代替UILabel解决错误。

替换:

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


为我修复了iOS6中的问题。没有在iOS 5上测试。

最后,这只是一个愚蠢的错误-

[mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(__bridge id)font range:boldRange];
应该读到:

[mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[UIColor blueColor].CGColor range:boldRange]; 

在向NSMutableAttributedString添加属性时,我使用了一个错误的范围,因此出现了此错误。修正了射程修正了碰撞


编辑:还通过在属性字典中使用UITextAttributeFont获得了它,这在iOS 7中显然已被弃用,这只会让事情神秘地崩溃。替换项是NSForegroundColorAttributeName。

抱歉,刚才注意到那里的编辑没有多大意义。。我记不起我指的是哪把钥匙,但在你的情况下你可能会明白。基本上不要使用不推荐使用的密钥!
[mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(__bridge id)font range:boldRange];
[mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[UIColor blueColor].CGColor range:boldRange];