在后台运行进程,而用户仍然可以使用 UI [英] run a process in the background while user can still use the UI

查看:29
本文介绍了在后台运行进程,而用户仍然可以使用 UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在不锁定用户界面的情况下在后台运行数据库提取过程.

I am attempting to run a database fetch process in the background without locking the user interface.

目前我有一个按钮可以执行此操作,但我希望它是自动的,以便在用户浏览当前结果时可以获得更多结果.

Currently I have a button that does this, but I would like it to be automatic so that it can get more results as user is browsing current results.

这是按钮的代码,我想让它自动而不是锁定用户界面.此外,如果有一种方法可以暂停该过程,但如果用户转到另一个也非常有用的屏幕,则从中断处继续.

Here is the code that the button does, I would like to make this automatic and not lock the UI. Also if there is a way to pause the process, but continue where it left off if user goes to another screen that would also be very useful.

提前致谢!

-(IBAction)continueUpdatingResultsButtonPressed:(UIButton*)sender{
[findMoreButton removeFromSuperview];
[self continueFindingMoreRecipes]; //(do this in background without locking screen)
[self loadRefreshButton];//At completion load this button (a blinking button) to refresh the cells with new results

}

推荐答案

您可以使用的典型模式如下:

A typical pattern you can use is something like this:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // perform data processing here (done in the background)

    dispatch_async(dispatch_get_main_queue(), ^{
        // update user interface here (done on the main thread)
    });
});

这篇关于在后台运行进程,而用户仍然可以使用 UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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