22

「データの読み込み中」というメッセージと回転アクティビティインジケーターを含むアラートビューを表示したい。これどうやってするの?

4

7 に答える 7

27

注: このソリューションは、iOS 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];
于 2012-05-24T10:23:54.807 に答える
26

これは iOS 7 で動作します

addSubView は、iOS 7 以降の UIAlertView では機能しません。代わりにこれを試してください

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];
于 2014-09-17T19:12:31.963 に答える
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];

..この状況では UIActionSheet を使用することをお勧めします...

于 2011-02-05T12:14:26.380 に答える
6

アラート ビューのサブビューとして、ラベルとアクティビティ インジケーターを追加できます。あなたはこのようなことをしなければなりません...

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

    }
于 2012-09-23T10:15:23.563 に答える
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];
于 2012-08-07T07:22:24.090 に答える