-1

I am having trouble passing my NSMutableArray data from one view to the other.

My view transition works the following way

Send View -> Recipients View

Recipients View -> Send View

In the recipients view I am grabbing the people I want to send my data to. Once I grab the people using an array, I go back to my send view to send those people that data.

In my send view I have the following NSMutableArray

@property (nonatomic, strong) NSMutableArray *sendTo;

I initialize it in viewDidLoad like so:

self.sendTo = [[NSMutableArray alloc] init];

In my Recipients View I have the following NSMutableArray

@property (nonatomic, strong) NSMutableArray *recipientsArray;

I initialize it in the viewDidLoad like so:

self.recipientsArray = [[NSMutableArray alloc] init];

I also have a back button in this controller which tries to handle the passing of the data in the recipientsArray. Please note this array does have data in it up until the point of the view switch.

- (IBAction)back {
   SendView *send = [self.storyboard instantiateViewControllerWithIdentifier:@"View"];
   send.sendTo = [NSMutableArray arrayWithArray:self.recipients];
[self dismissViewControllerAnimated:YES completion:nil];
}

Any idea why the array in my Send View is returning nil?

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
qdwwdqw
  • 1
  • 2

1 Answers1

2

This code creates a brand new instance of SendView...

SendView *send = [self.storyboard instantiateViewControllerWithIdentifier:@"View"];

This code sets the sendTo property on the brand new instance of SendView.

send.sendTo = [NSMutableArray arrayWithArray:self.recipients];

At the end of the back method, this instance of SendView goes out of scope and is gone forever.

In conclusion, you must get a reference to your existing instance of SendView in order to do anything meaningful.

CrimsonChris
  • 4,651
  • 2
  • 19
  • 30