Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is my variable ? objective-c

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
like image 770
algro Avatar asked May 31 '26 02:05

algro


1 Answers

I think I found it:

https://www.google.com/maps/place/Variable/@53.626739,10.025728,17z/data=!3m1!4b1!4m2!3m1!1s0x47b1885360fab615:0x584b82c7dfb5f612

Can you check if this Variable is yours?

besties phil

like image 156
hellphil Avatar answered Jun 01 '26 19:06

hellphil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!