문제

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];
}

}
도움이 되었습니까?

해결책

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;
        }
    

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top