Number of View :495

You surely often see on several application an UIAlertView telling you to wait until something happens (sending information to a server, etc) like this :

Well it can easily be done using a « normal » UIAlertView with some simple customization :


//::.. Preparing a new Alert then show it ..::
UIAlertView *alert;
//::.. this is an Alert with NO buttons ..::
alert = [[[UIAlertView alloc] initWithTitle:@"Configuring Preferences\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
//::.. create a new UIActivityIndicator ..::
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

//::.. place it into the UIAlert and center it ..::
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];

//::.. That's it ;)  ..::

Now, when you want to make it disappear, you must « simulate » the user touch on the normal Cancel button like this :


[alert dismissWithClickedButtonIndex:0 animated:YES];

Dernière recherches:

  • cutmaster:

    Good idea.
    But you must keep in mind that, to dismiss your alert, the UIAlertView * alert must be placed in your .h file to keep a pointer on it ;-)

Laisser un commentaire