ฉันค่อนข้างใหม่กับอุปกรณ์ iOS และคิดว่าฉันเข้าใจการส่งข้อมูลไปยังตัวควบคุมมุมมอง ชัดเจนว่าไม่. ฉันกำลังพยายามส่งข้อมูลภาพจาก ViewController หลักไปยัง ViewController ลูกที่แสดงแบบโมฆะ ฉันคิดว่าปัญหามีบางอย่างเกี่ยวกับวิธีการส่งวัตถุไปยังตัวควบคุมมุมมองที่นำเสนอแบบโมเดอเรเตอร์แทนที่จะส่งไปยังสแต็กการนำทาง ด้านล่างนี้เป็นรหัสจากผู้ปกครองและลูกที่เกี่ยวข้องกับปัญหาที่ฉันมี
จาก 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;
}
นี่คือใน Child.h ของฉัน
@property (nonatomic, strong) UIImage *backgroundImage;
นี่คือลูกของฉัน.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;
}
ฉันได้นำเข้าตัวควบคุมมุมมองลูกของฉันไปยังคลาสหลักของฉันแล้ว