I load a custom object using :
NSArray* array = [[NSBundle mainBundle] loadNibNamed:@"MyViewItem" owner:nil options:nil];
MyViewItem* myBaseItem = [array objectAtIndex:0];
In order not to perform the loadNibNamed action like a hundred times in the several loops I have to do, I plan to use this object as a "base" object that i'll fill with differents informations, but always based on the same design (like in an UICollectionView actually).
My first move was to set in my loop something like :
for (int i = 0; i < x; i++ ) {
MyViewItem* newItem = [myBaseItem copy];
}
Unfortunately, MyViewItem class tried to accessed "copyWithZone", which i didn't implement. On this point, i tried to inherits NSObject on it (I think all NSObject implements "copy" method), but the issue remains with the same error. So I tried to inherits NSCopying, and to implement my copyWithZone method, which is the following (not working though) :
@interface MyViewItem : UIView <NSCopying>
// some stuff
@end
@implementation MyViewItem
// some stuff
- (id)copyWithZone:(NSZone *)zone
{
MyViewItem* copy = [[MyViewItem allocWithZone:zone] init];
// What should i do here ?
return copy;
}
@end
What am I missing ? I've read many issues concerning copy, but I couldn't solve mine :( Thanks !