在做类似于QQ空间评论消息的页面时,出现一个小问题:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendFormat:'
查错发现是如下的代码问题:
cell.clickReturnBlock = ^(NSString *commentStr){
Model *m = _dataArr[indexPath.row];
[m.commentStr appendFormat:@"\n我:%@",commentStr];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom];
};
也就是说model里面的修饰属性可能有问题@property (nonatomic, copy) NSMutableString *commentStr;(用于装已有评论,以及新增加的评论)
在修改成strong或者retain之后就OK没有报错了。
说明如下:
如果希望字串的值跟着赋值的字串的值变化,可以使用strong,retain。
版权声明:本文为博主原创文章,未经博主允许不得转载。