繁体   English   中英

制作NSMutableAttributedString的深层副本时出现问题

[英]Problems Making a Deep Copy of NSMutableAttributedString

我试图做出的深层副本NSMutableAttributedString称为text使用其他NSMutableAttributedString称为textBackup 两者都是设置为@property (nonatomic, retain) ,我按如下方式创建备份:

NSMutableAttributedString *textBackupTemp = [self.text mutableCopy];
self.textBackup = textBackupTemp;
[textBackupTemp release];

然后稍后,当发生某种情况时,我需要还原副本:

NSMutableAttributedString *textTemp = [self.textBackup mutableCopy];
self.text = textTemp;
[textTemp release];

这似乎工作正常,但是下次我访问如下text

[self.text.string characterAtIndex: self.cursor.position-1]

我收到以下错误:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString characterAtIndex:]: Range or index out of bounds'

字符串大小已更改为1,而不是应有的43。 这里可能发生了什么...

编辑:更新了问题。

就我而言,这只是一个愚蠢的错误,我为我的textBackup实例变量添加了textBackup @property(nonatomic, assign) 我将其更改为retain ,现在一切正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM