objective-c - 在另一种方法中添加事件指示器以避免挂起

标签 objective-c ios xcode reachability

我已将 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 的作用,但您确实想确保您有类似 [activityIndi​​cator startAnimating] 的东西。至少对于正常的事件指示器,您需要手动将其打开。

关于objective-c - 在另一种方法中添加事件指示器以避免挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11803987/

相关文章:

ios - 哪些 OSX 图像格式与 IOS 兼容

ios - authorize.net ios sdk 中的 "The authentication type is not allowed for this method call"错误

ios - UIStatusBar 风格与 UINavigationBar 一致

ios - Xcode Instruments 分配的总字节数太大

ios - 如何在 appdelegate 中推送导航?

objective-c - Mac OS X 开发的替代范例

objective-c - Xcode 4 中的 OCUnit 和 C++?

objective-c - 您如何找出在 Instruments 中保留对象的内容?

ios - 为什么选择其他分割后iOS分割控件的颜色无法恢复

ios - 如何确定 NSNumber 的真实数据类型?