代码写法如下:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
[selfshowAlert];
}
- (void)showAlert{
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"2秒后将消失"delegate:nil cancelButtonTitle:nilotherButtonTitles:nil];
[alertshow];
// 2秒后执行
[selfperformSelector:@selector(dimissAlert:)withObject:alertafterDelay:2.0];
}
- (void) dimissAlert:(UIAlertView *)alert {
if(alert){
[alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES];
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
}
@end
运行效果如下: