我已将 Apple 的 Reachability.h 实现到我的演示应用程序中。问题是我注意到我的应用程序在检查连接时停止了。
因此,我添加了一个事件指示器(来自 MBProgressHUD )。但该指示器没有动画。它也会随着应用程序而停止。
因此,我考虑将事件指示器放在与主线程不同的另一个线程中,但它仍然没有动画。
注意:我经验不足
更新:另外,我尝试过 native 事件指示器,但没有成功。
- (void)anotherThread
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
// Set determinate mode
HUD.mode = MBProgressHUDModeDeterminate;
HUD.delegate = self;
HUD.labelText = @"loading";
// myProgressTask uses the HUD instance to update progress
[HUD showWhileExecuting:@selector(crazyCounter) onTarget:self withObject:nil animated:YES];
[pool release];
}
最佳答案
UI 代码应保留在主线程中。因此,您可能希望使用 GCD(中央调度)将检查连接代码放入另一个线程中,而不是将事件指示器放入另一个线程中。完成后,您可以删除或隐藏事件指示器。
PS。我不太确定MBProgressHUD
的作用,但您确实想确保您有类似 [activityIndicator startAnimating]
的东西。至少对于正常的事件指示器,您需要手动将其打开。
关于objective-c - 在另一种方法中添加事件指示器以避免挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11803987/