Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
dismissViewControllerAnimated在iOS 9中不工作_Ios_Objective C_Uiviewcontroller_Ios9_Presentviewcontroller - Fatal编程技术网

dismissViewControllerAnimated在iOS 9中不工作

dismissViewControllerAnimated在iOS 9中不工作,ios,objective-c,uiviewcontroller,ios9,presentviewcontroller,Ios,Objective C,Uiviewcontroller,Ios9,Presentviewcontroller,我有一个名为NewsViewController的UIViewController子类,它有一个从按钮操作调用的完成块属性。控制器设置并显示在另一个视图控制器中,如下所示: newsViewController.completionBlock = ^{ [self dismissViewControllerAnimated:YES completion:nil]; }; UINavigationController *navigationController = [[UINavigat

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

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

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:newsViewController];
[self presentViewController:navigationController animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
    [self dismissViewControllerAnimated:YES completion:nil];
});
在iOS 10中,这一切都可以正常工作,但在iOS 9中,该视图并没有被忽略。如果我在那里设置断点,它确实会被击中

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

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

我用GCD试过如下:

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

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:newsViewController];
[self presentViewController:navigationController animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
    [self dismissViewControllerAnimated:YES completion:nil];
});
我还尝试过将解雇调用放入一个方法中,然后调用

[self performSelectorOnMainThread:@selector(dismissModalView) withObject:nil waitUntilDone:NO];
实际上,我并不认为问题在于线程,因为在完成块中调用
[NSThread isMainThread]
会返回YES

延迟呼叫它

[self performSelector:@selector(dismissModalView) withObject:nil afterDelay:0.1];
在另一个视图控制器上调用Disclose

我尝试在
导航控制器
self.presentedViewController
self.presentingViewController
上调用它

直接从NewsViewController调用Disclose

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

顺便说一句。为了好玩,我试着从
presentViewController
方法的完成块中调用disclose方法,但它确实被解除了。

尝试以下代码:

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

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

    }];
}

我终于找到了问题所在,这是出乎意料的。问题是,
NewsViewController
显示在我的登录视图控制器上。此控制器允许用户使用触摸ID登录,因此它在其
viewdideappear
方法中请求触摸ID提示。显然,这会导致对当前视图的否定,而且似乎只有在iOS 9中才会出现这种情况(嗯,也许不仅如此,但在iOS 10中似乎效果不错)。

我不确定这样做能实现什么。使用您的代码,我将在关闭后再次显示
NewsViewController
。这根本不是我想要的,而且它也不能解决我的问题(首先不能解除)。您需要在完成时解除它,然后只写解除,而不在完成块中写入任何内容。您的代码将给我一个无限循环。在完成块中,您将再次显示相同的视图控制器。因此,当观点被驳回时,它将再次出现。正如你从我最初的问题中看到的,我已经尝试过这种方法。但无论如何,我现在已经找到了问题的根源。