Because it is NSCopyingnot so good in deep (recursive) copies of object plots. For example, [NSArray copy]copies a list of objects, not the objects themselves. Object schedules are better served NSCoding. Which in a happy coincidence is supported UIView.
If you want to copy a custom view with properties, you will need to maintain NSCoding. For example.
@interface SKCustomCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel* nameLabel;
@property (strong, nonatomic) IBOutlet UIView* topView;
@end
static NSString* propertiesKey = @"SKCustomCellProperties";
@implementation SKCustomCell
@synthesize nameLabel;
@synthesize topView;
- (id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder: aDecoder];
[self setValuesForKeysWithDictionary: [aDecoder decodeObjectForKey: propertiesKey]];
return self;
}
- (void) encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder: aCoder];
[aCoder encodeObject: [self dictionaryWithValuesForKeys: [[NSArray alloc] initWithObjects: @"nameLabel", @"topView", nil] forKey: propertiesKey];
}
@end
source
share