我试图在后台运行数据库获取过程而不锁定用户界面。
目前我有一个按钮可以执行此操作,但我希望它是自动的,以便在用户浏览当前结果时可以获得更多结果。
这是按钮执行的代码,我想使其自动执行而不锁定用户界面。此外,如果有一种方法可以暂停该过程,但如果用户转到另一个屏幕,则从中断处继续,这也将非常有用。
提前致谢!
-(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
}
您可以使用的典型模式如下所示:
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)
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)