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
iPhone-有关MBProgressHUD、Sudzc、Web服务和NSThread的帮助_Iphone_Objective C_Web Services_Nsthread_Uiactivityindicatorview - Fatal编程技术网

iPhone-有关MBProgressHUD、Sudzc、Web服务和NSThread的帮助

iPhone-有关MBProgressHUD、Sudzc、Web服务和NSThread的帮助,iphone,objective-c,web-services,nsthread,uiactivityindicatorview,Iphone,Objective C,Web Services,Nsthread,Uiactivityindicatorview,我有以下代码,它连接到一个web服务并返回一个类别数组 我正在为SOAP web服务使用以下包装器: ..以及活动指示器的以下MBProgressHUD: 我想有一个HUD进度指示器,指示它正在连接和获取结果。我目前正在使用MBProgressHUD来实现所需的效果,但是我注意到它工作不太正常。在加载和显示mytableView中的实际单元格之前,进度指示器消失。我还在应用程序的不同区域使用MBProgressHUD,但通常每次我连接到web服务时都会获取结果 有没有人能告诉我如何修复下面的

我有以下代码,它连接到一个web服务并返回一个类别数组

我正在为SOAP web服务使用以下包装器:

..以及活动指示器的以下
MBProgressHUD

我想有一个HUD进度指示器,指示它正在连接和获取结果。我目前正在使用
MBProgressHUD
来实现所需的效果,但是我注意到它工作不太正常。在加载和显示my
tableView
中的实际单元格之前,进度指示器消失。我还在应用程序的不同区域使用
MBProgressHUD
,但通常每次我连接到web服务时都会获取结果

有没有人能告诉我如何修复下面的代码以使其正常工作?我认为这可能与以下事实有关:回调方法是在显示进度指示器之后启动的。不太清楚如何使用回调方法正确实现
MBProgressHUD

这是我试图“尝试”让它工作的可怕尝试

- (void)showHUD {
    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];

    // Add HUD to screen.
    [self.navigationController.view addSubview:HUD];

    // Register for HUD callbacks so we can remove it from the window at the right time.
    HUD.delegate = self;

    HUD.labelText = @"Loading";

    // Show the HUD while the provided method executes in a new thread
    [HUD showWhileExecuting:@selector(runLocalNotificationHandler) onTarget:self withObject:nil animated:YES];
}

- (void)runLocalNotificationHandler {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    [self performSelectorOnMainThread:@selector(connectToService) withObject:nil waitUntilDone:YES];

    [pool release];
}

- (void)connectToService {
    Service1 *service = [[Service1 alloc] init];
    [service GetCategories:self action:@selector(handlerGetCategories:)];
    [service release];
}

- (void)handlerGetCategories:(id)value {
    // parse objects returned from array, populate array, reload table view data, etc
}

不要在主线程上执行网络操作,因为这会阻塞UI。在您的情况下,
MBProgressHUD
将不会设置动画,甚至不会显示


所以不要使用
performSelectorOnMainThread
。而是直接调用方法
connectToService
。当您在执行时调用
showWhileExecuting
时,
MBProgressHUD
将自行分离新线程。如果您在执行回调的情况下使用
MBProgressHUD
,则还有另一种方法。在开始后台处理之前,先初始化HUD

MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
而不是

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
然后将以下内容放入回调方法中:

[MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];

这样,您就可以准确地知道HUD何时显示和关闭。至少,通过查看使用新方法后的变化,它将帮助您调试真正的问题所在。

通过修改我的实用程序类,最终解决了这个问题。我表演了两次主选择器

您所说的是执行以下操作:[HUD showWhileExecuting:@selector(connectToService)ontTarget:self withObject:nil animated:YES]这与我预期的工作方式不符,因为HUD仅出现一小会儿,然后在显示结果之前消失,并且从不触发回调方法。