UIView with uiindicator sethidden = No not working after sethidden = YES

I have a uiView covering the screen with a label and uiindicator that runs when i am doing a network call.

Now here's the problem. I have initialized like this in viewdidload

[self.UiIndicator_view setHidden:YES];
[self.UiIndicator_label setHidden:YES];
[self.UiIndicator_indicator setHidden:YES];

On the network call i have called

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
 {
            [self ShowIndicator:@"Syncing Data"];

            if([self CheckNetwork])
                [HttpMethods GetHeaderDataForAppHttp];
            dispatch_async(dispatch_get_main_queue(), ^
            {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Network Error"
                                                                  message:@"You have no network connection. Please connect to a network to sync data."
                                                                 delegate:self
                                                        cancelButtonTitle:@"Ok"
                                                        otherButtonTitles:nil];

                [alertView show];
                [self StopIndicator];
            });
});

and the methods are as follows

-(void)ShowIndicator:(NSString*)labelText
{
    [self.UiIndicator_view setHidden:NO];
    [self.UiIndicator_label setHidden:NO];
    [self.UiIndicator_label setText:labelText];
    [self.UiIndicator_indicator setHidden:NO];
    [self.UiIndicator_indicator startAnimating];
}

-(void)StopIndicator
{
    [self.UiIndicator_view setHidden:YES];
    [self.UiIndicator_label setHidden:YES];
    [self.UiIndicator_indicator setHidden:YES];
    [self.UiIndicator_indicator stopAnimating];
}

Now the problem. The code runs perfectly fine when i start the app for first time. The call goes to dispatch_asyn, i see a UIView with label and indicator and after the call returns to main thread, the uiview and indicator disappears and i get the alertview if no data was fetched.

I have given the user an option to manually call the same function if data could not be fetched at first attempt. Here the issue arises, i can see in NSLOG that the method has been called, http request is fired, but i cannot see the uiview with indicator, even the elements and buttons that are supposed to be behind the uiview are not clickable (this means that there is a UIVIEW on top, but i cant see it). after some time i get the uialeart which means the call has completed.

Does setting uiview hidden = yes nullify it or something like that? i am not able to get this simple issue.

Answers


You are calling [self ShowIndicator:@"Syncing Data"]; on a background queue.

Only ever update the UI on the Main Queue.

More specifically:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
    [self ShowIndicator:@"Syncing Data"]; <<<< THIS IS YOUR PROBLEM

Need Your Help

question about jump in MIPS

assembly mips cpu-architecture

What does the PCGPRLEN-1..28 means here?? Where does this 4 bit comes from?

Read local file from Google App with Python

python google-app-engine file-upload

I'm trying to upload files to the blobstore in my Google App without using a form. But I'm stuck at how to get the app to read my local file. I'm pretty new to python and Google Apps but after some...