-[NSConcreteAttributedString addAttributes:range:]: unrecognized selector sent to instance

在往NSMutableAttributedString 中添加属性的时候,报错unrecognized selector sent to instance。

这是因为在类中添加属性的时候,设置成了copy,系统创建成员变量的时候,类型就是NSConcreteAttributedString,不可变字符串,改成strong就可以了。

错误代码:

@property (nonatomic, copy) NSMutableAttributedString * mutableText;

正确代码:

@property (nonatomic, strong) NSMutableAttributedString * mutableText;

Add a Comment

您的电子邮箱地址不会被公开。