I have the following:
Class 1:
.h file:
@interface class1 : UIViewController
@property (assign,nonatomic) int number;
.m file:
- (void)viewDidLoad
{
[super viewDidLoad];
number=1;
}
Class2:
.h file:
@interface class2 : UIView{
class1 *Controller;
}
@property (retain,nonatomic) class1 *controller;
but if access the number variable from anywhere in the second class the value is 0 any of you knows why?
Is the class already open and retained somewhere (i.e. your navigation stack)? If so you can then safely access and modify variables because they are already initialized. If not that’s probably why you’re getting 0 returned.
Another way is to create and maintain a data singleton that all view controllers can draw data from easily and you can then reference that data singleton to modify and change values.
Assuming the view controller is already initialized and active you can then do something like this: