复制 UIImageView 子类
我的数组中有几个对象。这些对象来自 UIImageView
子类。
这些对象的类有几个@synthesize
d 属性。
在某些时候,我必须在数组上给定位置的不同坐标处创建对象的副本。然后我这样做:
id objectToDuplicate = [myArray objectAtIndex:x];
id newObject = [objectToDuplicate copy];
CGPoint newCenter = [objectToDuplicate center];
newCenter.x = newCenter.x + 10;
newCenter.y = newCenter.y + 10;
[newObject setCenter:newCenter];
[self.view addSubview:newObject];
[newObject release];
当这段代码运行时,什么也没有发生。我的意思是,没有创建具有 10 像素偏移的对象,并且我在控制台中看到以下消息:
** ... copyWithZone:]:无法识别的选择器发送到实例... **
对象具有多个元素,例如文本框、标签和具有阴影、发光等的图像,并且新对象必须具有文本颜色、阴影、发光、大小、图像等的值与原始值相同。
我认为 UIImageView 具有 NSCopying 协议。如果这是问题,我该如何实施?
请不要向我发送文档,我已阅读它们,这就是我在这里询问的原因。请给我一些实际的例子。
谢谢。
I have several objects in an array. These objects are from a UIImageView
subclass.
These objects' class has several @synthesize
d properties.
At some point I have to create a duplicate of an object in a given position on the array at a different coordinate. Then I do:
id objectToDuplicate = [myArray objectAtIndex:x];
id newObject = [objectToDuplicate copy];
CGPoint newCenter = [objectToDuplicate center];
newCenter.x = newCenter.x + 10;
newCenter.y = newCenter.y + 10;
[newObject setCenter:newCenter];
[self.view addSubview:newObject];
[newObject release];
When this code runs, nothing happens. I mean, no object is created with a 10 pixel offset and I see this message in the console:
** ... copyWithZone:]: unrecognized selector sent to instance ... **
The objects have several elements such as text boxes, labels, and images that have shadow, glow, etc., and the new object has to have the same values for text colors, shadows, glows, size, images, etc., as the original.
I thought UIImageView
had the NSCopying
protocol in place. If this is the problem, how do I implement that?
Please refrain from sending me to the docs, I have read them and this is why I am asking here. Please give me practical examples.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在哪里读到
UIImageView
实现NSCopying
?事实并非如此,您必须自己为您的子类执行此操作。Where did you read that
UIImageView
implementsNSCopying
? It doesn't, you have to do that yourself for your subclass.