iOS NSMutableAttributedString 因无法识别的选择器而崩溃

标签 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          

最佳答案

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

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

如果您传入 NSAttributedString,则它将不起作用。 (看起来 NSAttributedString 应该是 NSString 的子类,但事实并非如此。)

关于iOS NSMutableAttributedString 因无法识别的选择器而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26666647/

相关文章:

ios - Worldpay 的 Cocoa pods 安装问题

c# - 如何禁止在 uipopovercontroller 后面的 View 上进行交互

android - 是否可以保护加密 key 不被 iOS/Android 中的恶意应用程序读取?

ios - IOS 中带有确认对话框的 Segue

ios - 为什么 AVPlayerItem 没有触发它的通知?

iphone - "Refreshing"iPhone/Mac OSX 上的 XML feed

ios - 我可以在一个应用程序中集成 UIViewController 和 UICollectionViewController 吗?

objective-c - obj-c 的 Ruby 解析器

ios - 更改更新核心数据属性的删除方法

xcode - 仅在播放视频时使用横向模式。代码。 IOS 7