Objective c 功能A完成后3秒启动功能B(使用MBProgressHUD)
我想在函数完成几秒钟后显示一个UIActionSheet,该函数是用函数B完成的 如果我这样做,效果会很好:Objective c 功能A完成后3秒启动功能B(使用MBProgressHUD),objective-c,multithreading,function,mbprogresshud,Objective C,Multithreading,Function,Mbprogresshud,我想在函数完成几秒钟后显示一个UIActionSheet,该函数是用函数B完成的 如果我这样做,效果会很好: main function { [self function A] [self performSelector:@selector(function B) withObject:nil afterDelay:5]; } 但我使用MBProgressHUD作为活动指示器: main function { [HUD showWhileExecuting:@selector(funcion
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,但看起来我无法延迟该函数。您的问题是HUD在主线程上被调用,并且没有设置为等待。因此,它会触发函数A,然后立即调用函数B的performSelector。如果希望函数B正确执行,则必须在函数A的末尾调用它