I'm trying to pass a UIView to another class - which kinda works, but I can't retain the pointer...
in my .h file I declare the view:
UIView *someView;
I add the property
@property (nonatomic, retain) UIView *someView;
And in the .m-file I synthesize the property
@synthesize someView;
Then I have a method to set the view (which is set in the .h file as well - believe me :):
-(void)makeViewPointer:(UIView *)myView{
someView = [[UIView alloc] init];
someView = myView;
for(UIView *aView in someView.subviews){
NSLog(@"tag %d", aView.tag);
}
}
So far, everything's working. When I log the someView, I get a pointer and all the subviews are accessable.
I'm calling this method from another class - which seems to work fine.
NOW - I have an IBAction set up to do something with that view after a button is clicked
-(IBAction)doSomething:(id)sender{
NSLog(@"show the view %@", someView);
for(UIView *aView in someView.subviews){ // doesn't output anything
NSLog(@"tag %d", aView.tag);
}
}
At this point, the someView-var is empty again - WHY????
I assumed, that when I use @property (nonatomic, retain), the variable gets retained automatically?
I also tried to retain the variable upon initializing:
someView = [[UIView alloc] retain];
doesn't work
or
someView = [[UIView alloc] init];
[someView retain];
doesn't work either...
What on earth am I doing wrong???
Thanks for any help!