开发者

ImagePicker in view hierarchy problem

I can't figure out the most effective and "elegant" method for doing some task. The problem definition is: I want to display several views, one of them is the ImagePicker with camera roll source.

The hierarchy looks similar to this: MAIN VIEW ---> PICKER ---> IMAGE PROCESSING VIEW When the user tap "back button" UI has to allow backward displaying.

I have tried several options:

1.

a) MAIN VIEW presents picker view modally. b) In didFinishPickingMediaWithInfo delegate method dismiss picker modal view and after that invoke presentModalViewController with IMAGE PROCESSING VIEW.

Sample code:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage* pickedImage = [info valueForKey:UIImagePickerControllerEditedImage];
    LastViewController* vc = [[LastViewController alloc] init];
    vc.mainImage = pickedImage;

    [self dismissModalViewControllerAnimated:NO];

    [self presentModalViewController:vc animated:NO];
}

Problem is that, it doesn't works, cause controller can't display next modal after dismissing another (previouse won't disappear immediately, MAIN isn't active immediately, and can't present the new one).

2. MAIN VIEW presents IMAGE PROCESSING VIEW modally, but immediately after that IMAGE PROCESSING VIEW is presenting picker view modally, waiting for done, dismissing picker and user can see IMAGE PROCESSING VIEW with image from library.

Sample code:

in some action of main view controller:

ImageProcessViewController *vc = [[ImagePro开发者_如何学运维cessViewController alloc] initWithNibName:@"ImageProcessViewController" bundle:nil];
vc.delegate = self;
vc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:vc animated:NO];
[vc release];

in ImageProcessViewController:

- (void)viewDidLoad {
    [super viewDidLoad];

    //some UI init here

    if(self.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
        UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
        ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        ipc.delegate = self;
        ipc.allowsEditing = YES;
        [self presentModalViewController:ipc animated:NO];
        [ipc release];
    }
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage* pickedImage = [info valueForKey:UIImagePickerControllerEditedImage];
    self.mainImage = pickedImage;

    [self dismissModalViewControllerAnimated:NO];
}

Problem is that, i can't call presentModalViewController in viewDidLoad method because it won't work (it is too early in view controller live cycle I guess). I tried also in viewDidAppear, but in that case I have to set some ivar flag, to display picker view only once and empty IMAGE PROCESSING VIEW is displayed for short time before image picker view and i don't want this.

3. I tried to figure out how to use Navigation Controller to do this, beacause UIImagePickerController is using his nav controller, but this is private structure and documentation says programmers can't do that.

Please give me some suggestions because I really lost my way at the moment


In your main view controller, use viewDidAppear:animated: - this will be called when the modal transition has finished. You can safely start another modal transition from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜