我如何首先关闭模态视图控制器? [英] How do i get dismiss modal view controller to happen first?

查看:46
本文介绍了我如何首先关闭模态视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [picker dismissModalViewControllerAnimated:YES];

...

}

不幸的是,在关闭模式视图控制器之前,它将运行其余代码(可能需要几秒钟).我如何才能先将其关闭,然后再运行其余代码?

Unfortunately, it runs the rest of the code (which can take a few seconds) before dismissing the modal view controller. How can i make it dismiss it first, and then run the rest of the code?

推荐答案

在返回到主运行循环(即函数返回)之前,它不会关闭模式视图控制器或进行任何其他UI更新.

It won't dismiss the modal view controller or do any other UI updates until it gets back to the main run loop (i.e. the function returns).

如果您要花费大量时间来完成任务,则应在后台线程而不是主线程上执行该任务.通常的事情是使用

If you have a task that is going to take a noticeable amount of time to complete, you should perform it on a background thread instead of on the main thread. The usual thing is to use performSelectorInBackground:withObject:; but do remember that any UI updates (e.g. when the operation is complete) must be done on the main thread, so your background method may have to use performSelectorOnMainThread:withObject:waitUntilDone:.

如果您喜欢块,可以使用

If you prefer blocks, you could use dispatch_async instead:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
    // background operation
});

如果您有许多后台操作,还可以查看

If you have a number of background operations, you could also look into NSOperationQueue for the background operation.

这篇关于我如何首先关闭模态视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆