Set UIImage of a new view and display it
-
20-08-2019 - |
Question
I'm trying to set the image of a new view. I set the controller's image an then display the view. But in the controller's viewDidLoad, no image is available.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
EditPictureSaveViewController *editPictureController = [EditPictureSaveViewController alloc];
[editPictureController initWithNibName:@"EditPictureSaveView" bundle:[NSBundle mainBundle]];
UIImageView *imageView = [ [ UIImageView alloc ] initWithImage: image ];
[imageView setImage:image];
[editPictureController setPreview:imageView];
[self.navigationController pushViewController:editPictureController animated:YES];
Solution
That's because viewDidLoad is called by
[editPictureController initWithNibName:@"EditPictureSaveView" bundle:[NSBundle mainBundle]];
after the NIB is loaded.
editPictureController's image property (which I assume is a UIImageView - confusing!) is not set until after this.
Do whatever you're doing in viewDidLoad in the viewWillAppear: method instead - your image property will be set when pushViewController:animated: calls viewWillAppear:.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow