I'm struggling to pass a NSMutable array from a Modal View controller back to the view controller I came from.
This is my current method:
FirstViewController.h
#import "SecondViewController.h"
@property (strong, nonatomic) IBOutlet NSMutableArray *passedRecipientsArray;
FirstViewController.m
@synthesize passedRecipientsArray = _passedRecipientsArray;
- (void)viewDidAppear:(BOOL)animated {
NSLog(@"passedRecipientsArray: %@", self.passedRecipientsArray);
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"addContact"]){
UINavigationController *nav = [segue destinationViewController];
SecondViewController *secondViewController = (SecondViewController *)nav.topViewController;
secondViewController.emailContact = @"TRUE";
}
}
SecondViewController.h
@property (strong, nonatomic) IBOutlet NSMutableArray *selectedContactsArray;
SecondViewController.m
@synthesize passedRecipientsArray = _passedRecipientsArray;
- (void)closeWindow
{
if([self.selectedContactsArray count] != 0){
NSLog(@"PASS ME: %@", self.selectedContactsArray);
FirstViewController *firstViewController = [[FirstViewController alloc] init];
if(firstViewController.passedRecipientsArray == nil) firstViewController.passedRecipientsArray = [[NSMutableArray alloc] init];
firstViewController.passedRecipientsArray = self.selectedContactsArray;
[self dismissModalViewControllerAnimated:YES];
}
}
Is there a better way of doing this? I've tried to used this: How to pass object on modal view's dismissal but get very confused.
Does anyone have a good tutorial/clear easy way of doing what I'm after? Can anyone tell me where I'm going wrong?