ViewController custom property
Trying to set a custom property(value) for a ViewController( e.g.- FirstViewController).
FirstViewController.h
//..
int value;
}
@property (assign) int value;
FirstViewController.m
@synthesize value;
-(void)showValue{
self.value = 3;
NSLog(@"%d", self.value);
}
Here works fine, but when I want to change the value of this variable (value) from another ViewController (ZeroViewController) nothing happens, and in viewDidLoad method of FirstViewController NSLog(@"%d", self.value) i get value == 0; Look the way how I do it.
ZeroViewController.h
FirstViewController* firstViewController;
}
@property (nonatomic, retain) FirstViewController* firstViewController;
ZeroViewController.m
FirstViewController *aFirstView = [[FirstViewController alloc]init];
self.firstViewCon开发者_JAVA技巧troller = aFirstView;
[aFirstView release];
firstViewController.value = 1;
NSLog(@" %d", firstViewController.value);
FirstViewController.m
-(void)viewDidLoad{
NSLog(@"%d", self.value);
}
As I suppose here should be "1", but console shows 0.
I think, that happens because I initialize my FirstViewController in ZeroViewController, and when FirstViewController becomes active it initializes again and all values annul. Or maybe I am wrong.
For what I am doing this: I have 10 buttons in a ZeroViewController. I want FirstViewController to change its value (self.value) When I press any button.
E.G.
firstViewController.value = 123;
If it is possible to help, please, do so.
Thanks!
http://narod.ru/disk/571946001/TestingValues.zip.html
The project.
Solution: I've assigned my view's property in the method when I change the views.
精彩评论