I am having problem here regarding data lost on NSDictionary (or whatever data type I am trying to pass between view controllers). I am passing the data as I will show on code below. But after passing and then accessing the data again, I received a null
object.
FirstViewController.m
-(void)showSecondViewController{
SecondViewController *secondVC = [SecondViewController new];
NSMutableDictionary *passedData = [[NSMutableDictionary alloc]init];
[passedData setObject:@"First Object" forKey:@"first_obj"];
[passedData setObject:@"Second Object" forKey:@"second_obj"];
[secondVC setData:passedData];
[self performSegueWithIdentifier:@"SecondViewControllerSegue" sender:self];
}
In my SecondViewController.h
@interface SecondViewController : UIViewController
{
NSDictionary *passedDataContainer;
}
-(void)setData(NSDictionary *)data;
And on SecondViewController.m
-(void)setData(NSDictionary *)data{
passedDataContainer = data;
}
From this I am assuming that I have my NSDictionary
from my FirstViewController
, but when I used it, say for example...
-(void)usePassedData{
NSLog(@"Display Passed Data from FirstViewController: %@",passedDataContainer);
}
In this code snippet, the output will be
Display Passed Data from FirstViewController: (null)
I hope I have explained the case well. I have checked some possible fixes that I found here on SO like for example, this post ---> iOS NSDictionary pass through function. I will be glad if I will know what is the cause of this, I am new to Objective-C.
P.S. I am using ARC.
Thanks.