-dismissModalViewControllerAnimated:适用于 iPhone,不适用于 iPad

发布于 2024-09-25 10:42:35 字数 543 浏览 3 评论 0原文

我无法让 -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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挖个坑埋了你 2024-10-02 10:42:35

我第一次将 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...)

情域 2024-10-02 10:42:35

我想将此作为评论发布,但我无法这样做。

是应该调用 dismissModelViewControllerAnimated: 的主视图控制器。您可以在呈现的视图控制器中调用 [[selfparentViewController]dismissModalViewControllerAnimated:] 或在协议中定义一个方法来关闭模态视图控制器并在主视图控制器中实现该协议,将其设置为所呈现视图控制器的委托并从中调用方法。你的做法是错误的。它可能会也可能不会解决您的问题。

更新(代码示例在注释中不可用):

在 MainViewController 上,您应该有类似的东西,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // In this case is inside a tableviewmethod, but it could really be an action associated with a button.

    DetailViewController *controller = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
    [controller setDelegate:self]; // The delegate is the parent and is assigned, not retained.

    // Modal presentation style is only used on iPad. On iPhone is always full screen.
    // [controller setModalPresentationStyle:UIModalPresentationFullScreen];

    [controller setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentModalViewController:controller animated:YES];
    [controller release]; // It will be deallocated upon dismissal.
}

-(void)dismissDetailViewControllerAndProcessData:(NSDictionary *)data {

    // Do something with the data passed.
    [self processData:data];

    // Dismiss the modalviewcontroller associated with this viewcontroller.
    [self dismissModalViewControllerAnimated:YES];
}

而在作为模态视图控制器呈现的详细视图控制器上,唯一需要的是类似的东西,

-(void)actionBack:(id)sender {

    // Call the delegate method. If you just need to dimiss the controller, just
    // call
    // [[self parentViewController]dismissModalViewControllerAnimated:YES];
    // and don't even bother to set up a delegate and a delegate method.

    [delegate dismissDetailViewControllerAndProcessData:nil]; // Call the parent dismissal method.
}

但如果该应用程序在 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

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // In this case is inside a tableviewmethod, but it could really be an action associated with a button.

    DetailViewController *controller = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
    [controller setDelegate:self]; // The delegate is the parent and is assigned, not retained.

    // Modal presentation style is only used on iPad. On iPhone is always full screen.
    // [controller setModalPresentationStyle:UIModalPresentationFullScreen];

    [controller setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentModalViewController:controller animated:YES];
    [controller release]; // It will be deallocated upon dismissal.
}

-(void)dismissDetailViewControllerAndProcessData:(NSDictionary *)data {

    // Do something with the data passed.
    [self processData:data];

    // Dismiss the modalviewcontroller associated with this viewcontroller.
    [self dismissModalViewControllerAnimated:YES];
}

while on the detail view controller presented as modal view controller, the only thing needed is something like this

-(void)actionBack:(id)sender {

    // Call the delegate method. If you just need to dimiss the controller, just
    // call
    // [[self parentViewController]dismissModalViewControllerAnimated:YES];
    // and don't even bother to set up a delegate and a delegate method.

    [delegate dismissDetailViewControllerAndProcessData:nil]; // Call the parent dismissal method.
}

but if the application is running fine on iPhone, it should run just as fine on the iPad as iPhone app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文