gpt4 book ai didi

ios - 如何在 Objective-C 中调用下一个方法之前更新 UIView

转载 作者:行者123 更新时间:2023-11-28 22:36:21 27 4
gpt4 key购买 nike

我正在尝试在开始下载数据之前更新屏幕上的 textView。现在,它只会在所有下载完成后更新 View 。如何在下载之前或下载期间执行此操作?

编辑:我希望 self.textView.text = @"Connection is good, start syncing..."; 在下载开始前更新 UI。但现在,它只会在下载完成后更新。

这是代码的样子。

if ([self.webApp oAuthTokenIsValid:&error responseError:&responseError]) {
self.textView.text = @"Connection is good, start syncing...";
[self.textView setNeedsDisplay];

[self performSelectorInBackground:@selector(downloadCustomers:) withObject:error];
}

我是新手,还没有了解线程的工作原理,但根据我的阅读,downloadCustomers 函数应该使用后台线程离开主线程来更新 UI。

最佳答案

if ([self.webApp oAuthTokenIsValid:&error responseError:&responseError]) {
self.textView.text = @"Connection is good, start syncing...";
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self downloadCustomers];
dispatch_async(dispatch_get_main_queue(), ^{
//Do whatever you want when your download is finished, maybe self.textView.text = @"syncing finished"
});
});
}

关于ios - 如何在 Objective-C 中调用下一个方法之前更新 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15873104/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com