ios 在presentViewController中应该完成什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13025026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what should go into completion in presentViewController?
提问by lakesh
I am using presentViewController
in xcode and not sure what should go into completion.
我presentViewController
在 xcode 中使用,不确定应该完成什么。
The code given by xcode documentation:
xcode 文档给出的代码:
- (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?
什么应该进入完成?
回答by Midhun MP
You can use the below code instead:
您可以改用以下代码:
[self presentViewController:second animated:YES completion:^{ }];
or you can simply pass NULL
或者你可以简单地传递 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.
完成块用于在呈现视图控制器后执行任何任务,完成块中编写的代码只有在呈现视图后才会执行。
回答by abhishekkharwar
@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];
回答by Nimit Parekh
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
有关更多详细信息,请查看苹果论坛讨论
回答by Michael
Swift 2.0
斯威夫特 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)