Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what should go into completion in presentViewController?

Tags:

ios

iphone

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?

like image 314
lakshmen Avatar asked Oct 23 '12 06:10

lakshmen


People also ask

What is present Modally?

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.

How do you go full screen on iOS 13?

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 .


4 Answers

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.

like image 156
Midhun MP Avatar answered Oct 04 '22 22:10

Midhun MP


@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];
like image 34
abhishekkharwar Avatar answered Oct 04 '22 23:10

abhishekkharwar


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

like image 29
Nimit Parekh Avatar answered Oct 04 '22 23:10

Nimit Parekh


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)
like image 24
Michael Avatar answered Oct 04 '22 22:10

Michael