ios 奇怪的警告解除模态视图控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12261008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Strange warning dismissing modal view controller
提问by Sparviero
I'm working on iOS 6. My application has a standard navigation controller with embedded a CustomViewController. In this controller I create a modal view like this:
我在 iOS 6 上工作。我的应用程序有一个标准的导航控制器,其中嵌入了一个 CustomViewController。在这个控制器中,我创建了一个模态视图,如下所示:
-(IBAction)presentModalList:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
StationsListViewController *list = [storyboard instantiateViewControllerWithIdentifier:@"StationsListViewController"];
[list setStationsData: [self.stationsData allValues]];
[self presentModalViewController:list animated:YES];
}
The modal controller show perfectly but dismissing generates a warning. The dismiss method in this controller is:
模态控制器显示完美,但关闭会产生警告。这个控制器中的dismiss方法是:
-(IBAction)backToMap
{
[self dismissModalViewControllerAnimated:YES];
}
The warning generated is Warning:
生成的警告是警告:
Attempt to dismiss from view controller < UINavigationController: 0x1ed91620 > while a presentation or dismiss is in progress!
在演示或关闭正在进行时尝试从视图控制器 < UINavigationController: 0x1ed91620 > 关闭!
Any clues about that?
有什么线索吗?
Thanks
谢谢
采纳答案by Yoni Hassin
Targeting iOS6, this is what worked for me:
针对 iOS6,这对我有用:
if (![self.presentedViewController isBeingDismissed])
[self.presentedViewController dismissViewControllerAnimated:YES
completion:nil];
回答by JDx
I realise this is a late answer but maybe this will help someone else looking for a solution to this, here is what I did:
我意识到这是一个迟到的答案,但也许这会帮助其他人寻找解决方案,这是我所做的:
-(IBAction)backToMap
{
if (![[self modalViewController] isBeingDismissed])
[self dismissModalViewControllerAnimated:YES];
}
For me, i found that line of code was being called multiple times, I couldn't find out why so this was the easiest fix.
对我来说,我发现那行代码被多次调用,我找不到原因,所以这是最简单的解决方法。
回答by Kyle Clegg
Thanks JDx for getting me on the right track. I adapted it to form this solution, which will remove the warning without using functions that are deprecated in iOS 6:
感谢 JDx 让我走上正轨。我对其进行了修改以形成此解决方案,它将在不使用 iOS 6 中已弃用的函数的情况下删除警告:
-(IBAction)backToMap
{
if (![self.presentedViewController isBeingDismissed]) {
[self dismissViewControllerAnimated:YES completion:^{}];
}
}
回答by JAWZ apps
I found this approach to be unreliable - say one case in five I'd still see the error.
我发现这种方法不可靠 - 假设五分之一的情况我仍然会看到错误。
My solution was to use the completion block to set a flag which controls whether or not it's safe to dismiss - that way you don't need to check whether or not the view is being dismissed.
我的解决方案是使用完成块来设置一个标志来控制是否可以安全解除——这样你就不需要检查视图是否被解除。
-(IBAction)presentModalView:(id)sender {
:
self.canDismiss = NO;
[self presentViewController:aVC animated:YES completion:^{
self.canDismiss = YES;
}];
:
}
In the bit of code where the dismiss occurs, just check the flag:
在发生解雇的代码位中,只需检查标志:
-(void)dismisser {
:
if (self.canDismiss) {
[self dismissViewControllerAnimated:YES completion:nil];
}
:
}
Hey presto, no more errors!
嘿,快,没有更多错误了!
回答by giuseppe
You can do whatever you want after the completion of the dismiss method as:
完成dismiss方法后,您可以做任何您想做的事情:
-(IBAction)backToMap
{
[self dismissViewControllerAnimated:YES
completion:^{
//Do something here
}];
}