xcode 应用程序试图以模态方式呈现主动控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8074766/
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
Application tried to present modally an active controller
提问by master_gracey
I have searched for and found various q/a on this error, but have not been able to find any specific help for my issue (at least that my minimal experience allows me to understand).
我已经搜索并找到了有关此错误的各种问答,但无法找到针对我的问题的任何具体帮助(至少我的最少经验让我能够理解)。
I am loading a UIView from the app's main menu, which in turn has several button options (call it submenu). One of these goes back to the main menu without issue ([self dismissModalViewControllerAnimated:YES];
). Another button loads a UITableView (separate view controller), which loads fine. However, I want a button within this UITableView to go back to the submenu. When I use the above mentioned code, it goes all of the way back to the main menu. I can't seem to find a way to create an action that goes back to the submenu UIView (submenu).
我正在从应用程序的主菜单加载 UIView,该菜单又具有多个按钮选项(称为子菜单)。其中之一可以毫无问题地返回主菜单 ( [self dismissModalViewControllerAnimated:YES];
)。另一个按钮加载一个 UITableView(单独的视图控制器),它加载得很好。但是,我希望此 UITableView 中的按钮返回到子菜单。当我使用上面提到的代码时,它会一直回到主菜单。我似乎无法找到一种方法来创建返回到子菜单 UIView(子菜单)的操作。
When I try to do a standard ['uitableviewcontrollername' presentModalViewController:submenuView animated:YES];
I get the error Application tried to present modally an active controller(I get the same error if I replace uitableviewcontrollername with self.
当我尝试执行标准时,['uitableviewcontrollername' presentModalViewController:submenuView animated:YES];
我收到错误应用程序试图以模态呈现活动控制器(如果我将 uitableviewcontrollername 替换为 self.
The error makes sense in that I understand that it is already active, but what I need help with is, what exactly is the proper way to do what I've described above? Thanks for your time.
该错误是有道理的,因为我知道它已经处于活动状态,但是我需要帮助的是,执行上述操作的正确方法是什么?谢谢你的时间。
采纳答案by master_gracey
For my specific needs, the following did the trick for getting back from thetableview:
对于我的特定需求,以下是从 thetableview 返回的技巧:
[self.mapLegendViewController dismissModalViewControllerAnimated:YES];
[self.mapLegendViewController dismissModalViewControllerAnimated:YES];
Gregory's point is noted though, and I recommend reading the link he made as it is interesting as to how iPhone/iPad each handle these actions.
不过,有人注意到了 Gregory 的观点,我建议阅读他制作的链接,因为 iPhone/iPad 各自如何处理这些操作很有趣。
回答by gregory
I believe the proper way to dismiss a modal view is to use delegation as defined in here.
我相信关闭模态视图的正确方法是使用此处定义的委托。
In practice you define a method on the 'menu view' that will dismiss the active modal view by calling the usual :
实际上,您在“菜单视图”上定义了一个方法,该方法将通过调用通常的方式关闭活动模式视图:
- (void) notifytoclose {
[self dismissModalViewControllerAnimated:YES];
}
You call it from the menu view but it will close the active modal on top of it. Then you define a delegate property on the modal table view controller, set it to the instance of the menu view, and in the method that closes the table view you call :
您从菜单视图调用它,但它会关闭其顶部的活动模式。然后在模态表视图控制器上定义一个委托属性,将其设置为菜单视图的实例,并在关闭表视图的方法中调用:
[delegate notifytoclose];
The use of [self dismissModalViewControllerAnimated:YES] to close the current instance is not always working although the circumstances are not clear to me. I also noticed differences between iPAd and iPhone behaviour.
尽管我不清楚情况,但使用 [self deniedModalViewControllerAnimated:YES] 关闭当前实例并不总是有效。我还注意到 iPad 和 iPhone 行为之间的差异。