-dismissModalViewControllerAnimated:适用于 iPhone,不适用于 iPad
我无法让 -dismissModalViewControllerAnimated: 在 iPad 上工作(作为 iPhone 应用程序)。由于某种原因,它似乎没有做任何事情。
我在 MainViewController 中调用 -presentModalViewController:animated: ,之后我尝试从呈现的视图控制器调用 -dismissModalViewController (使用 [selfmissModalViewController] strong>),据我所知,它将请求转发到 MainViewController。我还尝试在呈现的视图控制器中设置委托(viewControllerAboutToBePresented.delegate = self;),然后调用[self.delegate解雇ModalViewController:YES]。当我在 iPad 上运行 iPhone 应用程序时,这两种方法似乎都不起作用。
如何关闭 iPad 上的模态视图控制器?
I'm having trouble with getting the -dismissModalViewControllerAnimated: to work on the iPad (as an iPhone app). For some reason it doesn't seem to do anything.
I call -presentModalViewController:animated: in MainViewController, after which I've tried calling the -dismissModalViewController from the presented view controller (using [self dismissModalViewController]), which I understand forwards the request to the MainViewController. I've also tried setting a delegate in the presented view controller (viewControllerAboutToBePresented.delegate = self;), and then calling [self.delegate dismissModalViewController:YES]. Neither approach seems to do anything when I run the iPhone app on the iPad.
How can I dismiss the modal view controller on the iPad?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我第一次将 iPhone 项目移植到 iPad 时遇到了这个问题 -
[selfmissModalViewControllerAnimated:]
悄然失败了。该项目在 OpenGL 背景上使用 Cocoa 视图控制器,我认为这与此有关。由于截止日期非常紧迫,我没有时间弄清楚发生了什么,所以我只是将模态视图添加为当前视图控制器的子视图,并在完成后将其删除。 (是的,一个黑客,但这对你来说是时间尺度......)
I had this the first time I ported an iPhone project to the iPad - it was
[self dismissModalViewControllerAnimated:]
that was quietly failing. The project was using Cocoa view controllers over an OpenGL background, and I thought it was something to do with that.Because of the ridiculously tight deadline, I had no time to work out what was going on, and so I just added the modal view as a subview of the current view controller, and removed it when I was done. (Yeah, a hack, but that's timescales for ya...)
我想将此作为评论发布,但我无法这样做。
是应该调用 dismissModelViewControllerAnimated: 的主视图控制器。您可以在呈现的视图控制器中调用 [[selfparentViewController]dismissModalViewControllerAnimated:] 或在协议中定义一个方法来关闭模态视图控制器并在主视图控制器中实现该协议,将其设置为所呈现视图控制器的委托并从中调用方法。你的做法是错误的。它可能会也可能不会解决您的问题。
更新(代码示例在注释中不可用):
在 MainViewController 上,您应该有类似的东西,
而在作为模态视图控制器呈现的详细视图控制器上,唯一需要的是类似的东西,
但如果该应用程序在 iPhone 上运行良好,它在 iPad 上应该与 iPhone 应用程序一样运行良好。
I woud post this as a comment, but I'm unable to do so.
Is the main view controller that should call dismissModelViewControllerAnimated:. You can either call [[self parentViewController]dismissModalViewControllerAnimated:] in the presented view controller or define a method in a protocol that dismiss the modal view controller and implement the protocol in the main view controller, set it as the delegate of the presented view controller and call the method from it. You are doing it the wrong way. It might or might not solve your issue.
Update (code sample isn't available on comments):
On the MainViewController you should have something like this
while on the detail view controller presented as modal view controller, the only thing needed is something like this
but if the application is running fine on iPhone, it should run just as fine on the iPad as iPhone app.