代码之家  ›  专栏  ›  技术社区  ›  JoBu1324

-dismissModalViewControllerAnimated:适用于iPhone而不是iPad

  •  1
  • JoBu1324  · 技术社区  · 16 年前

    我打电话来 -演示文稿控制器:动画: 在MainViewController中,之后我尝试调用 -解除ModalViewController [自动解除ModalViewController] ),我知道它会将请求转发到MainViewController。我还尝试在显示的视图控制器中设置委托( ),然后打电话 [自我授权解雇控制员:是的] . 当我在iPad上运行iPhone应用程序时,这两种方法似乎都没用。

    我怎样才能关闭iPad上的模态视图控制器?

    2 回复  |  直到 16 年前
        1
  •  1
  •   Echelon    16 年前

    [self dismissModalViewControllerAnimated:] 那是悄然的失败。这个项目是在OpenGL背景下使用Cocoa视图控制器的,我认为这与此有关。

    由于截止日期太紧了,我没有时间去弄清楚到底发生了什么,所以我只添加了模态视图作为当前视图控制器的子视图,并在完成后将其删除。(是的,一个黑客,但这是你的时间表…)

        2
  •  0
  •   sigsegv    16 年前

    我想把这个作为一个评论,但我不能这么做。

    是应该调用 [[self 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应用程序一样好。

    推荐文章