I initialize a view(Image) through:
Image *myImageView = [[Image alloc]init];
myImageView.myId = randomImageNumber;
[myImageView initWithImage:myImage];
At the Image class I do a Log(LOG1) and get the previously set randomImageNumber. Later on, in the very same Class, I do a second Log(LOG2). Why does my second log have no value anymore ?
Here my implementation-file of the Class Image:
@synthesize myId;
-(id) initWithImage: (UIImage *) anImage
{
NSLog(@"LOG1%d",myId);
if ((self = [super initWithImage:anImage]))
{
self.userInteractionEnabled = YES;
}
return self;
}
}
-(void)touchesBegan...
....
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"LOG2%d",myId);
}
The "return self" empties myId which i declared in the header-file and which was set at the initialisation. How do I prevent that ?
my Headerfile looks like this:
@interface Image : UIImageView
{
int myId;
}
@property (assign) int myId;
@end