IPhone - Help with MBProgressHUD, Sudzc, Web Services and NSThread

I have the following code that connects to a web service and returns an array of categories.

I use the following shell for SOAP web services:

http://www.sudzc.com/

.. and MBProgressHUDfor the activity indicator:

https://github.com/jdg/MBProgressHUD

I would like the HUD progress indicator to indicate that it connects and captures the results. Currently, I use MBProgressHUDto achieve the desired effect, but I notice that it does not work correctly. The progress bar disappears before the actual cells in mine are loaded and displayed tableView. I also use MBProgressHUDin different areas of my application, but usually every time I connect to a web service to get results.

Can someone lead me in the right direction regarding how to fix the code below to work correctly? I think this may relate to the fact that the callback method runs after the progress indicator is displayed. Not quite sure how to implement it correctly MBProgressHUDusing the callback method.

This is my terrible attempt to "try" to make it work.

- (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
}
+3
source share
3 answers

If you use MBProgressHUDin a situation where a callback is being made, there is another approach. Initialize the HUD before starting the background process with

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

instead

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];

and then enter the following in the callback method:

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

, , HUD . , , , , .

+6

, . MBProgressHUD .

performSelectorOnMainThread. connectToService . MBProgressHUD , showWhileExecuting.

+1

This ultimately led to a change in my Utility class. I performed the main selector twice!

0
source

Source: https://habr.com/ru/post/1789190/


All Articles