Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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 在另一种方法中添加活动指示器以避免挂起_Objective C_Ios_Xcode_Reachability - Fatal编程技术网

Objective c 在另一种方法中添加活动指示器以避免挂起

Objective c 在另一种方法中添加活动指示器以避免挂起,objective-c,ios,xcode,reachability,Objective C,Ios,Xcode,Reachability,我已经在我的演示应用程序中实现了苹果的Reachability.h。问题是,我注意到我的应用程序在检查连接时暂停 因此,我添加了一个活动指示器(来自)。但该指示器没有动画。它也会与应用程序一起暂停 所以,我想把活动指示器放在另一个不同于主线程的线程中,但它仍然没有动画 注意:我不是很有经验 更新:另外,我尝试了本机活动指示器,但没有成功 - (void)anotherThread { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]

我已经在我的演示应用程序中实现了苹果的Reachability.h。问题是,我注意到我的应用程序在检查连接时暂停

因此,我添加了一个活动指示器(来自)。但该指示器没有动画。它也会与应用程序一起暂停

所以,我想把活动指示器放在另一个不同于主线程的线程中,但它仍然没有动画

注意:我不是很有经验

更新:另外,我尝试了本机活动指示器,但没有成功

- (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(grandcentraldispatch)在另一个线程中抛出检查连接代码,而不是将活动指示器放入另一个线程。完成后,您可以删除或隐藏活动指示器

另外,我不太清楚
MBProgressHUD
的功能,但您确实希望确保您有类似
[activityIndicator startAnimating]
的功能。至少对于正常活动指示器,您需要手动打开它