I would like to know how can I load a new nib file after finishing with UIImagePicker Controller. So after the user takes a picture from the camera or albums, i would like to load a new nib for the user to do some editing. Below is the didFinishPickingMediaWithInfo. I can load an image to the current UIImageView or even send out and alertview, but even if I tried loading a new nib, it just goes back to currentview nib and no errors. Bear in mind that I’m a total ios noob, so if the method use is wrong, please let me know. Thanks in advance.
p.s. Just to add, even if I manage to load new nib, how do I pass the information from the previous nib? E.g. if I choose an image from nib2, how to pass it to nib3?
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
imageOverlay.image = [UIImage imageNamed:@"mask_overlay1.png"];
[imageOverlay release];
// Displaying image to the imageView
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Tried to load a new nib
UIView *currentView = self.view;
// Get the underlying UIWindow, or the view containing the current view.
UIView *theWindow = [currentView superview];
//remove the current view and replace with myView1
[currentView removeFromSuperview];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"createPhotoView"];
}
I have no idea what your app’s workflow is like, but if you need to display a new view after an image is chosen, you should probably do it by either pushing a new view controller on to a navigation controller, or by presenting it as a modal view.
This allows you to easily return to the previous screen where you were asked to pick a photo.
Let’s say that for your app, you decide to use a
UINavigationController.You would initialize a navigation controller with your first view controller as the root view controller.
Then, in your UIImagePicker delegate method, you would have something like this:
You create a subclass of
UIViewControllercalled CustomViewController, and pass it values by creating properties you can assign to (like valueToPass in my example).EDIT:
It is possible to just switch the visible view of a view controller. It is as simple as changing the value of
self.view. You could put two UIViews in the same XIB file, and put IBOutlets for both in your controller. You could have a header that looks like this:Then, in your controller code:
This works, but as far as I am aware, does not allow transitions. You could instead do this:
Both of these options work, and allow you to use the same view controller to control both views. However, if the views perform different tasks, they should be associated with different controllers. Using different controllers is similar if you set up a controller as a property in your header: