Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 功能A完成后3秒启动功能B(使用MBProgressHUD)_Objective C_Multithreading_Function_Mbprogresshud - Fatal编程技术网

Objective c 功能A完成后3秒启动功能B(使用MBProgressHUD)

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

我想在函数完成几秒钟后显示一个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,但看起来我无法延迟该函数。

您的问题是HUD在主线程上被调用,并且没有设置为等待。因此,它会触发函数A,然后立即调用函数B的performSelector。如果希望函数B正确执行,则必须在函数A的末尾调用它