- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
- message:[@"Alert"
- delegate:nil
- cancelButtonTitle:nil //NSLocalizedString(@"OK", @"OK") //
- otherButtonTitles:nil];
- //[alert setBounds:CGRectMake(alert.bounds.origin.x, alert.bounds.origin.y, alert.bounds.size.width, alert.bounds.size.height+30.0)];
- [alert show];
- UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
- // Adjust the indicator so it is up a few pixels from the bottom of the alert
- indicator.center = CGPointMake(alert.bounds.size.width/2, alert.bounds.size.height-40.0);
- [indicator startAnimating];
- [alert insertSubview:indicator atIndex:0];
- [indicator release];
- [NSTimer scheduledTimerWithTimeInterval:3.0f
- target:self
- selector:@selector(dismissAlert:)
- userInfo:[NSDictionary dictionaryWithObjectsAndKeys:alert, @"alert", @"testing ", @"key" ,nil] //nil.
- repeats:NO];
- NSLog(@"release alert");
- [alert release];
- -(void) dismissAlert:(NSTimer *)timer{
- NSLog(@"release timer");
- NSLog([[timer userInfo] objectForKey:@"key"]);
- UIAlertView *alert = [[timer userInfo] objectForKey:@"alert"];
- [alert dismissWithClickedButtonIndex:0 animated:YES];
- }
- //
- [timer invalidate];
- timer = nil;
- //该片段来自于http://www.codesnippet.cn/detail/171220138091.html
来源: http://www.codesnippet.cn/detail/171220138091.html