我正在努力将 NSMutable 数组从模态视图控制器传递回我来自的视图控制器。
这是我目前的方法:
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];
}
}
有没有更好的方法来做到这一点?我试过用这个:How to pass object on modal view's dismissal但很困惑。
有没有人有一个很好的教程/清晰的简单方法来做我所追求的?谁能告诉我哪里出错了?