使用UIImageView作为属性深度复制Objective-C对象 [英] Deep copy Objective-C objects with UIImageView as property
问题描述
我有一个对象,其属性为NSString,UIImageView和简单的变量,如BOOL,int和float。
I have an object with properties that are NSString, UIImageView and simple vars like BOOL, int and float.
我正在尝试创建该对象的深层副本。目的。为此,我对类和copyWithZone方法实现了NSCopying协议,例如:
I'm trying to create a deep copy of the object. For that I've implemented the NSCopying protocol to my class and the copyWithZone method like:
-(id)copyWithZone:(NSZone *)zone
{
iItem *clone = [[iItem alloc] init];
//iItem *clone = [super copyWithZone:zone];
clone.originalTransform = self.originalTransform;
clone.initialTransform = self.initialTransform;
clone.originalFrame = self.originalFrame;
clone.zOrder = self.zOrder;
clone.itemId = self.itemId;
clone.itemIdColor = self.itemIdColor;
clone.itemIdTexture = self.itemIdTexture;
clone.itemIdStyle = self.itemIdStyle;
clone.textureLevel = self.textureLevel;
clone.currentSizePercent = self.currentSizePercent;
clone.holdItem = self.holdItem;
clone.isInverted = self.isInverted;
clone.delegate = self.delegate;
clone.mergedFrame = self.mergedFrame;
clone.selectedMergeView = [self.selectedMergeView copy];
clone.ScaleFactorScreen = self.ScaleFactorScreen;
clone.selectedFrameView = [self.selectedFrameView copy];
clone.selectedFrame = [self.selectedFrame copy];
clone.frameBeforeMovement = self.frameBeforeMovement;
//clone.touchBeginPoints = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
clone.touchBeginPoints = CFDictionaryCreateMutableCopy(NULL, 0, self.touchBeginPoints);
clone.contentMode = UIViewContentModeScaleAspectFit;
clone.animationImages = self.animationImages;
clone.image = [self.image copy];
clone.animationDuration = self.animationDuration;
clone.animationRepeatCount = self.animationRepeatCount;
[clone startAnimating];
clone.transform = self.transform;
clone.frame = self.frame;
clone.userInteractionEnabled = YES;
clone.multipleTouchEnabled = YES;
return clone;
}
iItem类继承自UIImageView类,因此我尝试调用super copyWithZone,但我出错了。对于要克隆的UIImageView对象,我收到SIGABRT消息'-[UIImageView copyWithZone:]:无法识别的选择器发送到实例0x210f50'。
The class iItem inherits from UIImageView class, so I tried to call super copyWithZone but I'm getting error. And for the UIImageView objects that I'm trying to clone I receive the SIGABRT message '-[UIImageView copyWithZone:]: unrecognized selector sent to instance 0x210f50'.
如何我可以复制具有UIImageViews,NSString和简单变量的对象的深层副本?
How can I make a deep copy of an object that have UIImageViews, NSString and simple vars?
推荐答案
最简单的方法是使用NSKeyedArchiver和假设您的对象符合NSCoder,则取消对NSKeyedUnarchiver的存档
Easiest way is to archive with NSKeyedArchiver and unarchive to NSKeyedUnarchiver assuming your objects conform to NSCoder
这篇关于使用UIImageView作为属性深度复制Objective-C对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!