2011-02-05 14 views

Odpowiedz

20

możesz dodać etykietę i wskaźnik aktywności jako podglądy widoku alertu. trzeba zrobić coś takiego

myAlertView = [[UIAlertView alloc] initWithTitle:@"Loading" message:@"\n\n" 
             delegate:self 
           cancelButtonTitle:@"" 
           otherButtonTitles:@"OK", nil]; 

UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] 
       initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
loading.frame=CGRectMake(150, 150, 16, 16); 
[myAlertView addSubview:loading]; 
[myAlertView show]; 

..better do korzystania z UIActionSheet w tej sytuacji ...

+0

dziękuję, będę używać UIActionSheet + UIActivityIndicatorView – Voloda2

+1

Dlaczego należy użyć UIActionSheet w tej sytuacji? (Wiem, że Apple prawdopodobnie by się z tobą zgadzał, ale chciałbym wiedzieć dlaczego). Nie korzystasz z prywatnych interfejsów API, prawda? – Nate

+3

Brakuje "[loading startAnimating]", a także są puste przyciski pokazujące. – jowie

27

UWAGA: To rozwiązanie nie będzie działać na systemie iOS 7 i nowszych.

To jest moje zdanie na jej temat:

alertView = [[UIAlertView alloc] initWithTitle:@"Submitting Entry" 
             message:@"\n" 
             delegate:self 
          cancelButtonTitle:nil 
          otherButtonTitles:nil]; 

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur 
[alertView addSubview:spinner]; 
[spinner startAnimating]; 
[alertView show]; 

i odwołuje w kodzie za pomocą:

[alertView dismissWithClickedButtonIndex:0 animated:YES]; 
+5

użyj 'spinner.center = CGPointMake (0.0, -spinner.frame.size.height); spinner.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 'aby zawsze ustawiać pokrętło w dolnej środkowej części ostrzeżenia, – MrTJ

+0

pokrętło się nie pokazuje. Mój alterView pokazuje tylko Zgłaszanie wpisu. Używam iOS 7. – coolcool1994

+0

@ coolcool1994 To nie zostało przetestowane na iOS 7.Odpowiedź od 2 lat temu;) – jowie

0
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alarm" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; 

UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] 
            initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
loading.frame=CGRectMake(125, 50, 36, 36); 
[loading startAnimating]; 
[alert addSubview:loading]; 
[alert show]; 
6

można dodać etykietę i activityindicator jako subviews swojego alertu widzenia. trzeba zrobić coś takiego ...

- (IBAction)showAlertWithActivity:(id)sender{ 

alerta = [[UIAlertView alloc] initWithTitle:@"Guardando datos..." 
              message:@"\n" 
              delegate:self 
            cancelButtonTitle:nil 
            otherButtonTitles:nil]; 

     UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
     spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur 
     [alerta addSubview:spinner]; 
     [spinner startAnimating]; 
     [alerta show]; 


     [self performSelector:@selector(close) withObject:self afterDelay:1]; 


    } 
    -(void)close{ 

     [alerta dismissWithClickedButtonIndex:0 animated:YES]; 

    } 
+0

Dzięki za twój wpis – SampathKumar

1

Dodaj ten w pliku .h UIAlertView *connectingAlert;

I Dodaj te dwie funkcje w plikach .m

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

następnie zadzwonić

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

To działa na iOS 7

addSubView nie działa na UIAlertView w systemie iOS 7 i nowszych wersjach. Spróbuj tego zamiast

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Loading data" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil]; 

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
[indicator startAnimating]; 

[alertView setValue:indicator forKey:@"accessoryView"]; 
[alertView show]; 

i odrzucić go

[alertView dismissWithClickedButtonIndex:0 animated:YES]; 
+0

To jest rozwiązanie, które działa na iOS 7 (Do tego komentarza bieżąca data). – OhadM

0

w Swift 3

let loadingAlertController = UIAlertController(title: "Loading", message: nil, preferredStyle: .alert) 

let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray) 
activityIndicator.translatesAutoresizingMaskIntoConstraints = false 

loadingAlertController.view.addSubview(activityIndicator) 

let xConstraint = NSLayoutConstraint(item: activityIndicator, attribute: .centerX, relatedBy: .equal, toItem: loadingAlertController.view, attribute: .centerX, multiplier: 1, constant: 0) 

let yConstraint = NSLayoutConstraint(item: activityIndicator, attribute: .centerY, relatedBy: .equal, toItem: loadingAlertController.view, attribute: .centerY, multiplier: 1.4, constant: 0) 

NSLayoutConstraint.activate([ xConstraint, yConstraint]) 

activityIndicator.isUserInteractionEnabled = false 
activityIndicator.startAnimating() 

let height: NSLayoutConstraint = NSLayoutConstraint(item: loadingAlertController.view, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 80) 

loadingAlertController.view.addConstraint(height); 

self.present(loadingAlertController, animated: true, completion: nil) 
Powiązane problemy