I am using presentViewController
in xcode and not sure what should go into completion.
The code given by xcode documentation:
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);
Example that i am using:
[self presentViewController:second animated:YES completion:<#^(void)completion#>];
What should go into completion?
Present Modally - Presents a view controller overtop the current view controller in various fashions as defined by the modal presentation and transition style - most commonly used to present a view controller in a sheet that animates up from the bottom. Example: Selecting Face ID & Passcode in Settings.
Initially, the default value is fullscreen for modalPresentationStyle, but in iOS 13 its changes to the UIModalPresentationStyle. automatic . If you want to make the full-screen view controller you have to change the modalPresentationStyle to fullScreen .
You can use the below code instead:
[self presentViewController:second animated:YES completion:^{ }];
or you can simply pass NULL
[self presentViewController:second animated:YES completion:NULL];
The completion block is used for doing any tasks after presenting the view controller , the code written inside the completion block will execute only after the view is presented.
@try this
[self presentViewController:second animated:YES completion:^{[self animationCompleted];}];
-(void)animationCompleted{
// Whatever you want to do after finish animation
NSLog(@"Animation Completed")
}
if you don't want to do anything on completion of animation
[self presentViewController:second animated:YES completion:NULL];
You can use the following code for the presenting the view
[[self navigationController] dismissViewControllerAnimated:YES completion:NULL];
Following is the code for the that
SecondViewController *second = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self presentViewController:second animated:YES completion:nil];
For more detail check the apple forum discussion
Swift 2.0
Handle something on completion
viewController.presentViewController(anotherViewController, animated: true, completion: {
// Whatever you'd like to do when presentViewController completes :)
})
Or do nothing on completion
viewController.presentViewController(anotherViewController, animated: true, completion: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With