I have a UIImageView that I’d like to load with a picture coming from an instance of UIImagePickerController in order to show a preview to the user. My app has a TabBarViewController and in order to hide the bar I’m showing both the picker and the preview modally.
The controller I use for the preview has been built on Interface Builder and it holds an empty UIImageView. When the picture has been taken, I was trying to set the image of the UIImageView but the IBOutlet was always nil. This is what I came up to in order to achieve what I was looking for:
[self.view addSubview:self.previewController.view];
[self.previewController.imageView setImage:self.scaledPicture];
[self presentModalViewController:self.previewController animated:YES];
I’m still not sure this is the right approach but if I don’t use the first line above, the self.previewController.imageView will be nil. The visual effect of the line has no impact because the modal view covers everything…
I checked the links in IB many times and they all appear to be correct.
Is this the right way to proceed?
If you have just created previewController, then its imageView will be nil because the view has not loaded. The reason that the first line seems to make it work is because it causes the view to load.
What you should do is have an
imageproperty on the previewController which you can assign here. Then load the image into theimageViewin the previewController’sviewDidLoad. This way, you’re also avoiding poking at another view controller’s views.