iOS UIAlertController UIAlertView 几秒钟消失的提示

复制代码
UIAlertView版(iOS9.0以后废弃)
//操作提示
- (void)showAlert:(NSString *)message disappear:(BOOL)disappear {
    dispatch_async(dispatch_get_main_queue(), ^{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:!disappear?@"OK":nil otherButtonTitles:nil, nil];
    [alert show];
    if (disappear) {
        double delayInSeconds = 1.2;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [alert dismissWithClickedButtonIndex:alert.cancelButtonIndex animated:YES];
        });
    }
         });
}

//调用
[self showAlert:@"介里系累容" disappear:YES];
复制代码
复制代码
UIAlertController版(苹果支持用的)
复制代码
//操作提示
- (void)showDismissWithTitle:(NSString *)title  message:(NSString *)message parent:(UIViewController *)parentController {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alert animated:YES completion:nil];

        double delayInSeconds = 1.2;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [alert dismissViewControllerAnimated:YES completion:nil];
        });
    });
}
复制代码

 

 

//调用
[self showDismissWithTitle:@"" message:@"累容载介里" parent:self];
复制代码

 

posted on   高彰  阅读(516)  评论(0编辑  收藏  举报

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

统计

点击右上角即可分享
微信分享提示