iOS NSMutableAttributedString崩溃使用无法识别的选择器

时间:2014-10-31 02:27:45

标签: ios objective-c ios7 nsstring unrecognized-selector

帮助!

崩溃发生在:

[emtionString replaceCharactersInRange:range withString:imageAndRangeDicArray[i][@"image"]];

NSMutableAttributedString替换为attributeString

这是堆栈跟踪:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableAttributedString _encodingCantBeStoredInEightBitCFString]: unrecognized selector sent to instance 0x7fe8f34f52f0'

    *** First throw call stack:
    (
        0   CoreFoundation                      0x0000000107e95f35 __exceptionPreprocess + 165
        1   libobjc.A.dylib                     0x0000000107b2ebb7 objc_exception_throw + 45
        2   CoreFoundation                      0x0000000107e9d04d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
        3   CoreFoundation                      0x0000000107df527c ___forwarding___ + 988
        4   CoreFoundation                      0x0000000107df4e18 _CF_forwarding_prep_0 + 120
        5   CoreFoundation                      0x0000000107db8195 __CFStringCheckAndReplace + 597
        6   CoreFoundation                      0x0000000107db7f1b -[__NSCFString replaceCharactersInRange:withString:] + 27
        7   Foundation                          0x00000001076da63e -[NSConcreteMutableAttributedString replaceCharactersInRange:withString:] + 337          

1 个答案:

答案 0 :(得分:1)

emtionString和imageAndRangeDicArray [i] [@" image"]是什么类型的?

根据文档,该方法需要NSString作为withString。

如果您传入的是NSAttributedString,那么它就无法工作。 (看起来NSAttributedString应该是NSString的子类,但它不是。)