dismissViewControllerAnimated 在 iOS 9 中不起作用

dismissViewControllerAnimated not working in iOS 9

我有一个名为 NewsViewControllerUIViewController 子类,它有一个从按钮操作调用的完成块 属性。控制器设置并呈现在另一个视图控制器中,如下所示:

newsViewController.completionBlock = ^{
    [self dismissViewControllerAnimated:YES completion:nil];
};

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:newsViewController];
[self presentViewController:navigationController animated:YES completion:nil];

在 iOS 10 中,这一切工作正常,但在 iOS 9 中,视图未被取消。如果我在那里放置一个断点,它就会被击中。

我尝试了以下但没有成功:

从主线程调用它(同步和异步)

我试过这样使用 GCD:

dispatch_async(dispatch_get_main_queue(), ^{
    [self dismissViewControllerAnimated:YES completion:nil];
});

我也尝试过将解雇调用放入一个方法中,然后调用

[self performSelectorOnMainThread:@selector(dismissModalView) withObject:nil waitUntilDone:NO];

我实际上不认为问题是线程,因为从完成块中调用 [NSThread isMainThread] returns 是。

延迟调用

[self performSelector:@selector(dismissModalView) withObject:nil afterDelay:0.1];

在另一个视图控制器上调用关闭

我试过在 navigationControllerself.presentedViewControllerself.presentingViewController 上调用它。

直接从 NewsViewController 调用 dismiss

在调用完成块的按钮动作中我直接调用了[self dismissViewControllerAnimated:YES completion:nil]

顺便说一句。只是为了好玩,我尝试从 presentViewController 方法的完成块调用 dismiss 方法,但它确实被解雇了。

尝试使用以下代码:

newsViewController.completionBlock = ^{
   [self performSelector:@selector(Dismiss) withObject:nil afterDelay:0.3];
};

 -(void)Dismiss
{
[self dismissViewControllerAnimated:YES completion:^{

    }];
}

终于找到问题所在了,有点出乎意料。问题是 NewsViewController 显示在我的登录视图控制器上。此控制器允许用户使用 Touch ID 登录,因此它在其 viewDidAppear 方法中请求 Touch ID 提示。显然,这与当前视图的取消混淆,而且似乎只在 iOS 9 中出现(好吧,也许不仅如此,但它似乎在 iOS 10 中工作正常)。