Refreshing Parent ViewController after dismissing ModalViewController

后端 未结 3 796
隐瞒了意图╮
隐瞒了意图╮ 2021-02-02 01:31

In my iOS app, a user can select an image from a list, upon which they are presented with a modal that contains the image and options to delete the image. If the user chooses t

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-02 01:57

    This may help anyone who have same problem on UIPopovePresentationController. From my experience, Allan's answer can resolve the same issue too.

    I've just have problem about Viewcontroller's delegate that present as UIPopoverPresentingController didn't send call to its root view. And Allan's answer can solved this fit.

    My sample code:

    -(IBAction)choosePic:(id)sender
    {
        UIButton *picButton = (UIButton *)sender;
    
        // Set PopoverPresentation view controller
    
        PicViewController *picVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PicViewController"];
    
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:picVC];
    
        picVC.preferredContentSize = CGSizeMake(500., 500.);
    
    
        // Set this function as described in Allan's answer
    
        picVC.dismissPopover = ^(UIViewController *controller, UIImage *image) 
        {
    
           _myImage = image;
    
           .....
    
           .....
    
           .....
    
        };
    
        navController.modalPresentationStyle = UIModalPresentationPopover;
    
        _picPopover = navController.popoverPresentationController;
    
        _picPopover.delegate = self;
    
        _picPopover.sourceView = self.view;
    
        _picPopover.sourceRect = [picButton frame];
    
        navController.modalPresentationStyle = UIModalPresentationPopover;
    
        navController.navigationBarHidden = YES;
    
        [self presentViewController:navController animated:YES completion:nil];
    
    }
    

提交回复
热议问题