Question

I am using ASIHTTP class to communicate with server. Now when any request done it is displaying processbar until request not server not respond or timeout. Now I want to make request when user click on yes button in alert view. When I am doing this processbar is just displaying for while. It is not displaying til the request complete.

- (IBAction)sendGratuity:(id)sender {

if([[txtAmount.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]>0){
    UIAlertView *confirmAlert = [[UIAlertView alloc] initWithTitle:@"Confirm"
                                                    message:@"Are you really want to send gratuity to this User?"
                                                   delegate:self
                                          cancelButtonTitle:@"No"
                                          otherButtonTitles:@"Yes", nil];
    [confirmAlert show];

}
else{
    [self sendGratuityRequest];  //if request made from here then it is working fine
}

AlertView method:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex==1){
    [self sendGratuityRequest];
}

}
Était-ce utile?

La solution

Is the progress bar added to the top level UIWindow?

My guess is that because UIAlertView creates its own UIWindow, your code in sendGratuityRequest is adding the bar to that window, which will get removed shortly after the button press.

Two possible solutions:

  1. Put your code in alertView:didDismissWithButtonIndex: instead of alertView: clickedButtonAtIndex:. (I'm not 100% sure this will fix it.)

  2. Use better logic to select the correct UIWindow. Proper code might look like this, but could be different depending on how your app uses UIWindows:

    NSEnumerator *frontToBackWindows = [[[UIApplication sharedApplication]windows]reverseObjectEnumerator];
    
    for (UIWindow *window in frontToBackWindows)
        if (window.windowLevel == UIWindowLevelNormal) {
            // Add the progress bar to this UIWindow
            break;
        }
    

Autres conseils

May be somewhere else you are changing value of networkActivityIndicatorVisible flag. Search [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; in your code.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top