Problem opening new ViewController after UIImagePickerController

前端 未结 2 394
小蘑菇
小蘑菇 2021-01-23 23:24

I am trying to open up a new view (UnprocessedPhotoViewController) immediately after the delegate function for my UIImagePickerController returns a \"didFinishPickingImage\".

2条回答
  •  盖世英雄少女心
    2021-01-23 23:35

    Implement viewDidAppear in your root view controller and based on member data decide to call showPhoto or not. The following example simply re-presents the UIImagePicker but any new modal view will work. viewDidAppear is called any time your root view controller’s view appears so you have to make sure the context is known when it is called. But it is the deterministic way to know that the modal view controller is gone.

    - (IBAction) showPicker: (id) sender
    {
        UIImagePickerController* picker = [[[UIImagePickerController alloc] init] autorelease];
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        picker.delegate = self;
        picker.allowsEditing = YES;
    
        [self presentModalViewController:picker animated:YES];
    }
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        imageChosen = YES;
    
        [self dismissModalViewControllerAnimated:YES];
    }
    
    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
    {
        imageChosen = NO;
    
        [self dismissModalViewControllerAnimated:YES];
    }
    
    - (void) viewDidAppear: (BOOL) animated
    {
        if ( imageChosen )
        {
            [self showPicker: self];
        }
    }
    

提交回复
热议问题