gpt4 book ai didi

ios - iOS performSelectorInBackground内部的performSelectorInBackground

转载 作者:行者123 更新时间:2023-12-01 18:59:22 40 4
gpt4 key购买 nike

似乎该函数调用[self updateUI];被嘘封锁。

boo是在另一个后台线程中运行还是与foo相同,如下面的代码?

[self updateUI]如何?不被嘘阻止吗?

- (void)MainFunction
{
[self performSelectorInBackground@selector(foo) withObject:nil];
}

- (void)foo
{
[self performSelectorInBackground@selector(boo) withObject:nil];

//updaate UI in MainThread
[self updateUI];
}

- (void)boo
{
//function here take long time to run;
}

最佳答案

在您的代码中,似乎在后台中调用foo,因此无法在后台线程中更新 UI,因为您需要在主线程中进行此操作。无论如何,performSelectorInBackground有点旧...以这种方式使用dispatcher:

- (void)MainFunction
{
[self foo];
}

- (void)foo
{
dispatch_async(dispatch_get_global_queue(DISPATCH_PRIORITY_DEFAUL, 0ull), ^{
[self boo];

dispatch_async(dispatch_get_main_queue(), ^{
//updaate UI in MainThread
[self updateUI];
};
};
}

- (void)boo
{
//function here take long time to run;
}

在这种情况下, updateUI 等待 boo ,但是如果您想先 updateUI ,并且 boo 何时完成无关紧要:
- (void)foo
{
dispatch_async(dispatch_get_global_queue(DISPATCH_PRIORITY_DEFAUL, 0ull), ^{
[self boo];
};

[self updateUI];
}

关于ios - iOS performSelectorInBackground内部的performSelectorInBackground,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23867970/

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