简体   繁体   中英

How to switch views when Iphone camera returns?

I am new to Iphone development. I am working on an application which involves two views. I have a camera button in view one which opens up the default Iphone camera. This is achieved by having this code in the IBAction for camera button in ViewOneController:

UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];

The view controller for the first view is also the UIImagePickerControllerDelegate for the camera. When the picture is clicked and the camera view returns to the function imagePickerController:didFinishPickingWithMediaInfo where I do this:

(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
 [self presentModalViewController:ViewTwoViewController animated:YES];
}

So basically all I am trying to achieve is from viewone click "take picture" ---> Open camera --> after camera is done jump to view two. Quite simmilar to what it is in the flickr app. However after I take the picture from camera my app returns to view one and view two is not shown. What am I missing here?

Also from a conceptual perspective I guess IOS keeps a stack of views for any app. When presentModalViewController is called the view is shown and it is added to the stack and when dismissModalViewController is called the view is removed from the stack and the parent view is show. Is that right?

Thanks.

You probably need to put the call to [self presentModalViewController:ViewTwoViewController animated:YES] in viewWillAppear which will be called after the picker view has been removed. You probably also need to surround the call with some check to only present viewTwo when applicable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM