I'm pretty new with the iOS stuff, and thought I understood passing data to a view controller. Apparently not. I am trying to pass image data from a parent ViewController to a child ViewController that is presented modally. I think the problem has something to with the way objects are passed to a modally presented view controller instead of one pushed onto the navigation stack. Bellow is the code from the parent and the child related to the problems I am having.
From the Parent.m:
- (IBAction)sort:(id)sender {
SortSelectViewController *ssvc = [self.storyboard instantiateViewControllerWithIdentifier:@"sort"];
ssvc.backgroundImage = [self screenshot];
[self performSegueWithIdentifier:@"sort" sender:self];
//The segue is linked from my parent view controller to my child with the identifier "sort"
}
- (UIImage *) screenshot {
CGRect rect = CGRectMake(0, 20, 640, 1116);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale);
[self.view drawViewHierarchyInRect:rect afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
return image;
}
This is in my Child.h
@property (nonatomic, strong) UIImage *backgroundImage;
This is my Child.m:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"%@", self.backgroundImage);
//This log will return nil when the program is run - clear sign data is not being correctly passed
self.backgroundImage = [self.backgroundImage applyDarkEffect];
self.imageView.image = self.backgroundImage;
}
I have imported my child view controller into my parent class