iOS UIAlertController到底是不是有Bug呢?

当需要在dismissViewControllerAnimated: completion:方法中do sth的时候发现了问题

ViewController.m 的代码如下

- (void)viewDidLoad {
    [super viewDidLoad];
  
    UIAlertController *vc = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否保存账号截图" preferredStyle:UIAlertControllerStyleAlert];
    [vc addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }]];
    [self presentViewController:vc animated:YES completion:nil];
}

- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
    [super dismissViewControllerAnimated:flag completion:completion];
    NSLog(@"%s", __func__);
}

结果发现:- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion方法中的NSLog(@"%s", __func__);方法触发了两次,这是为什么呢?

这是不是一个Bug呢?欢迎了解的小伙伴在评论区留言

你可能感兴趣的:(iOS UIAlertController到底是不是有Bug呢?)