I am trying to pass Array from one UIViewController
to other viewcontroller.
I tried using property (viewcontroller1.array).
I tried notifications (posting notification and adding observer ).
I tried NSUserDefaults
all are returning a null array.
Asked
Active
Viewed 117 times
-1
-
4Add your tried code. – Imad Ali Jun 19 '17 at 03:46
-
Possible duplicate of [Passing Data between View Controllers](https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Bista Jun 19 '17 at 06:15
2 Answers
1
in ViewController 1 from array is to passed
@interface demopreseViewController () {
NSArray* nameArr;
}
- (void)viewDidLoad {
[super viewDidLoad];
nameArr = [NSArray arrayWithObjects: @"Jill Valentine", @"Peter Griffin",nil];
NSLog(@"%@",nameArr);
}
- (IBAction)PresentAction:(id)sender {
ViewController2 *aviewcontroller = [self.storyboard instantiateViewControllerWithIdentifier:@"aa"];
aviewcontroller.array1 = nameArr;
[self presentViewController:aviewcontroller animated:YES completion:nil];
}
In viewController 2 Where array is to be passed
under ViewController2.h
@property (strong, nonatomic) NSArray *array1;
under ViewController2.m
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"parsed%@",_array1);
}
Array Data will be passed

iOS Geek
- 4,825
- 1
- 9
- 30
-
.I tried the above type steps already but still null array iam getting. is it mandatory to give like this " ViewController2 *aviewcontroller = [self.storyboard instantiateViewControllerWithIdentifier:@"aa"];". ? when I gave the above line iam getting unrecognized selector sent to instance error. ofcourse I had given the identifier with the name i specified to my storyboard.I have many storyboard files in the project? does it make difference if I give self.storyboard? – sampath Jun 19 '17 at 04:53
-
Did you tried using identifier of storyboard like Below UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; – iOS Geek Jun 19 '17 at 05:02
-
@sampath, `viewConrtoller2` is the name of view controller's class so you need to give yours. – vaibhav Jun 19 '17 at 05:05
-
I have tried below code and it worked. **MViewController *nextVC =(MViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"Service"]; ** – sampath Jun 19 '17 at 05:40
0
Define the property for Your Arrays
@Property(nonatomic, retain) NSArray *arrayName;
Secondly
ViewControllerClassName *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"StoryboardIdentifier"];
controller.array = arrayName;

Raza.najam
- 769
- 6
- 15