我在与获取-dismissModalViewControllerAnimated麻烦:在iPad工作(作为iPhone应用程序)。出于某种原因,它似乎并没有做任何事情。

我请 -presentModalViewController:动画:在MainViewController,之后我试图调用 -dismissModalViewController 从所呈现的视图控制器(使用的 [自dismissModalViewController ] ),我明白将请求转发到MainViewController。我也试着设置在所呈现的视图控制器委托(的 viewControllerAboutToBePresented.delegate =自我; ),然后调用的 [self.delegate dismissModalViewController:YES] 即可。这两种方法都好像当我运行在iPad上的iPhone应用程序做任何事情。

如何解雇iPad上的模态视图控制器?

有帮助吗?

解决方案

我有这个,我第一次移植的iPhone项目到iPad上 - 这是[self dismissModalViewControllerAnimated:]是静静地失败。该项目采用可可视图控制器在OpenGL的背景,我认为这是事做这一点。

因为可笑的期限紧迫,

,我没有时间制定出了什么事情,所以我刚才添加的模态视图为当前视图控制器的子视图,并删除它,我做的时候。 (是的,一个黑客,但是这对于时间表...雅)

其他提示

我woud张贴此作为一个评论,但我不能这样做。

是应该调用主视图控制器dismissModelViewControllerAnimated:。你可以呼叫的 [[自parentViewController] 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应用程序运行正常。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top