How can I show alertview with activity indicator?

后端 未结 7 2264
青春惊慌失措
青春惊慌失措 2020-11-30 09:52

I want to show alertview with message: \"Loading data\" and spinning activity indicator. How can I do this?

7条回答
  •  暖寄归人
    2020-11-30 10:24

    Add This in your .h file UIAlertView *connectingAlert;

    And Add these two functions in your .m files

    //show loading activity.
    - (void)startSpinner:(NSString *)message {
        //  Purchasing Spinner.
        if (!connectingAlert) {
            connectingAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(message,@"")
                                                     message:nil
                                                    delegate:self
                                           cancelButtonTitle:nil
                                           otherButtonTitles:nil];
            connectingAlert.tag = (NSUInteger)300;
            [connectingAlert show];
    
            UIActivityIndicatorView *connectingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
            connectingIndicator.frame = CGRectMake(139.0f-18.0f,50.0f,37.0f,37.0f);
            [connectingAlert addSubview:connectingIndicator];
            [connectingIndicator startAnimating];
    
        }
    }
    //hide loading activity.
    - (void)stopSpinner {
        if (connectingAlert) {
            [connectingAlert dismissWithClickedButtonIndex:0 animated:YES];
            connectingAlert = nil;
        }
        // [self performSelector:@selector(showBadNews:) withObject:error afterDelay:0.1];
    }
    

    then call

    [self startSpinner:@"Your message........"];
    [self stopSpinner];
    

提交回复
热议问题