iOS-UIAlertView彈框2秒後自動消失
阿新 • • 發佈:2019-01-06
程式碼寫法如下:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
[selfshowAlert];
}
/**
* 彈框提示
*/
- (void)showAlert{
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"2秒後將消失"delegate:
[alertshow];
// 2秒後執行
[selfperformSelector:@selector(dimissAlert:)withObject:alertafterDelay:2.0];
}
/**
* 移除彈框
*/
- (void) dimissAlert:(UIAlertView *)alert {
if(alert){
[alert dismissWithClickedButtonIndex:[alert cancelButtonIndex]
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
}
@end
執行效果如下: