功能 A 完成后 3 秒启动功能 B(使用 MBProgressHUD)
我想在函数完成后几秒钟显示一个 UIActionSheet,这是用函数 B 完成的。
如果我这样做,效果很好:
main function
{
[self function A]
[self performSelector:@selector(function B) withObject:nil afterDelay:5];
}
但我使用 MBProgressHUD 作为活动指示器:
main function
{
[HUD showWhileExecuting:@selector(funcion A) onTarget:self withObject:nil animated:YES];
[self performSelector:@selector(function B) withObject:nil afterDelay:5];
}
不起作用,函数 B 永远不会被调用。如果我将其切换到 [self function B] 它将被调用。我猜这是我还不明白的线程问题。如果我使用 [self PerformSelectorOnMainThread] 它将调用函数 B,但看起来我无法延迟该函数。
I want to show a UIActionSheet a couple seconds after a function finishes which is done with function B.
it works great if i do it like this:
main function
{
[self function A]
[self performSelector:@selector(function B) withObject:nil afterDelay:5];
}
but i am using MBProgressHUD as an activity indicator:
main function
{
[HUD showWhileExecuting:@selector(funcion A) onTarget:self withObject:nil animated:YES];
[self performSelector:@selector(function B) withObject:nil afterDelay:5];
}
does not work, function B never gets called. if i switch it to [self function B] it will be called. i'm guessing this is an issue with threading that i don't understand yet. if i use [self performSelectorOnMainThread] it will call function B but it doesn't look like i can delay that one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是 HUD 在主线程上调用并且未设置为等待。所以它会触发你的函数A,然后立即调用函数B的performSelector。如果你希望函数B正确执行,你必须在函数A的末尾调用它。
Your issue is that the HUD is called on the main thread and is not set to wait. So it fires off your functionA, then immediately calls your performSelector for function B. If you want function B to perform correctly, you will have to call it at the end of function A.