eXit_door 2013-07-08 02:54 采纳率: 0%
浏览 2152
已采纳

在ios中后退键关闭应用

下面的代码用来打开另一个视图控制器 (在myviewcontroller1.m中):

#import "contactvc.h"

contactvc *ii;

// ....

-(IBAction)passothervc:(id)sender
{
   //this code seems working OK.
   ii = [self.storyboard instantiateViewControllerWithIdentifier:@"contactvc"];
   [self presentViewController:ii animated:NO completion:nil];
}

下面的代码返回给主视图控制器:

-(IBAction)backToMain:(id)sender
{
   [self.view removeFromSuperview];
}

问题是在按后退键时会保持空黑屏幕。请指教。

  • 写回答

1条回答 默认 最新

  • ReyZhang 新星创作者: 移动开发技术领域 2013-07-08 03:15
    关注

    使用presentViewController 需要返回时,不是调用

    [self.view removeFromSuperview];
    

    而是有相应的关闭方法。presentViewController是一个模态窗口,可看做是web开发中的弹出窗口。相应的关闭代码是:

    [self dismissViewControllerAnimated:NO completion:nil];
    

      [self.view removeFromSuperview];
    

    它的作用是将当前视图从其父视图中移除。在一个viewcontroller中view为当前视图的base视图,如果将它移除会显示UIWindow的默认背景色,也就是你看到的黑色屏幕

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?