Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

presentViewController with dismiss block

This is what I would like. Present a UIViewController (UITableViewController) and in the presentViewController method incorporate a dismiss block.

So something like this:

[self presentViewController:vc 
    animated:YES 
    completion:nil 
    onDismiss:^{
        NSLog(@"dismissed")
    }
];

I tried implementing This SO solution because it looks like the exact thing of what I need but didn't quite figure out how it should be done. Anyone that can provide me with a detailed description?

Thanks!

like image 229
Ron Avatar asked Jun 15 '26 21:06

Ron


1 Answers

To clarify the discussion in the comments:

In your ContainerViewController's header define this function:

-(void)presentViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^)(void))completion dismissCompletion:(dispatch_block_t)dismissCompletion

and follow the rest of the instructions for the implementation of the function for ContainerViewController from here

Then in your ViewController call

[containerViewController presentViewController:presentedViewController animated:YES completion:<whatever> dismissCompletion:<whatever>]

If you're calling this from within a ContainerViewController you can call it on self if you're in SomeOtherViewController with a ContainerViewController (CVC) object call it on the CVC object.

like image 182
Shizam Avatar answered Jun 18 '26 09:06

Shizam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!