25

presentViewController在 xcode 中使用,不确定应该完成什么。

xcode 文档给出的代码:

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);

我正在使用的示例:

[self presentViewController:second animated:YES completion:<#^(void)completion#>];

应该完成什么?

4

4 回答 4

43

您可以改用以下代码:

[self presentViewController:second animated:YES completion:^{ }];

或者你可以简单地传递 NULL

[self presentViewController:second animated:YES completion:NULL];

完成块用于在呈现视图控制器后执行任何任务,完成块内编写的代码只有在呈现视图后才会执行。

于 2012-10-23T07:03:35.477 回答
16

@试试这个

[self presentViewController:second animated:YES completion:^{[self animationCompleted];}];


-(void)animationCompleted{

   // Whatever you want to do after finish animation

    NSLog(@"Animation Completed")

}

如果您不想在动画完成后做任何事情

[self presentViewController:second animated:YES completion:NULL];
于 2012-10-23T07:08:10.390 回答
3

您可以使用以下代码来呈现视图

  [[self navigationController] dismissViewControllerAnimated:YES completion:NULL];

以下是那个的代码

SecondViewController *second = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self presentViewController:second animated:YES completion:nil];

有关更多详细信息,请查看苹果论坛讨论

于 2012-10-23T07:04:24.360 回答
1

斯威夫特 2.0


完成后处理某事

viewController.presentViewController(anotherViewController, animated: true, completion: {
    // Whatever you'd like to do when presentViewController completes :)
})

或者完成后什么都不做

viewController.presentViewController(anotherViewController, animated: true, completion: nil)
于 2016-04-20T19:43:24.790 回答