I have gone through many questions in here but is still unable to find a solution to my problem. I have a class named ModelClass
and another class named ViewController
and yet another called ViewController2
. I have the following properties in ModelClass
:
@property (assign) int DataFromVC1;
@property (assign) int DataFromVC2;
I have the data collected from VC1 and VC2 and I correctly displayed the required data using NSLog from the corresponding view controllers. But when I try to send DataFromVC1
to VC2, and use NSLog to display 'DataFromVC1' from within VC2, it is showing 0
. But it is displaying the correct value when NSLog is called from VC1.
I used the following code segments to import the MainClass in the ViewController class implementations(just including the relevant parts):
#import "ModelClass.h"
@interface ViewController2 ()
{
ModelClass *MC;
}
@implementation ViewController
....
- (void)viewDidLoad
{
.....
MC = [[ModelClass alloc]init];
}
<function that gets the data>
{
.....
NSLog(@"%d",MC.DataFromVC1);
....
}
<function that sets the data>
{
.....
MC.DataFromVC2 = requiredData;
.....
}
And similar code in the other ViewController class as well. Why is the data set to zero while sending from one class to another? Thanks in advance.