我有2个视图,在第二个视图中我初始化了一个NSMutableArray
,我想将它传递回第一个视图。在第二个视图中,我有一个按钮,其中包含以下操作:
-(IBAction)back:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil]
}
通过这个动作,我从第二个ViewController返回到第一个ViewController,有没有办法从该动作传递NSMutableArray?
答案 0 :(得分:0)
如果您未使用prepareForSegue
,则可以使用NSUserDefaults
:
-(IBAction)back:(id)sender {
NSMutableArray *mutableArray = [[NSMutableArray alloc]init];
[[NSUserDefaults standardUserDefaults]setObject:mutableArray forKey:@"array"];
[self dismissViewControllerAnimated:YES completion:nil];
//I'm guessing you are going to load the viewController that's up next?
}
您可以在viewDidLoad中检索它,如下所示:
// to retrieve in maybe viewDidLoad?
NSArray * array = [[NSUserDefaults standardUserDefaults]arrayForKey:@"array"];
NSMutableArray *mutableArray = [array mutableCopy];