开发者

Copying a UIImageView subclass

开发者 https://www.devze.com 2023-03-05 22:13 出处:网络
I have several objects in an array. These objects are from a UIImageView subclass. These objects\' class has several @synthesized properties.

I have several objects in an array. These objects are from a UIImageView subclass.

These objects' class has several @synthesized 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 g开发者_运维技巧ive me practical examples.

Thanks.


Where did you read that UIImageView implements NSCopying? It doesn't, you have to do that yourself for your subclass.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号