2011-02-05 2 views

ответ

20

вы можете добавить ярлык и указатель активности в качестве подзонов вашего вида предупреждения. Вы должны сделать некоторые вещи, как этого

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, чтобы использовать UIActionSheet в этой ситуации ...

+0

спасибо, я буду использовать UIActionSheet + UIActivityIndicatorView – Voloda2

+1

Почему вы должны использовать UIActionSheet в этой ситуации? (Я знаю, что Apple, вероятно, согласится с вами, но я хотел бы знать, почему). Вы не используете какие-либо частные API, не так ли? – Nate

+3

Вам не хватает '[loading startAnimating]', а также отображаются пустые кнопки. – jowie

27

ПРИМЕЧАНИЯ: Это решение не будет работать на прошивке 7 и выше.

Это мой взгляд на него:

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

и увольняет в коде с помощью:

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

use 'spinner.center = CGPointMake (0.0, -spinner.frame.size.height); spinner.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 'всегда располагать прядильщик в нижней части вашего оповещения. – MrTJ

+0

spinner не отображается. В моем alterView отображается сообщение «Отправка записи». Я использую iOS 7. – coolcool1994

+0

@ coolcool1994 Это не было протестировано на iOS 7.Ответ от 2 лет назад;) – 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

вы можете добавить метку и activityindicator в качестве подвидов вашего оповещения зрения. Вы должны сделать некоторые вещи, как это ...

- (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

Спасибо за сообщение – SampathKumar

1

Добавить это в файле .h UIAlertView *connectingAlert;

И Добавьте эти две функции в ваших .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]; 
} 

затем вызвать

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

Это работает на прошивке 7

addSubView не работает в UIAlertView в iOS 7 и выше. Попробуйте вместо

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

и уволить его

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

Это решение, которое работает на iOS 7 (для комментариев текущая дата). – OhadM

0

В 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)