下面的代码用来打开另一个视图控制器 (在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];
}
问题是在按后退键时会保持空黑屏幕。请指教。
使用presentViewController 需要返回时,不是调用
[self.view removeFromSuperview];
而是有相应的关闭方法。presentViewController是一个模态窗口,可看做是web开发中的弹出窗口。相应的关闭代码是:
[self dismissViewControllerAnimated:NO completion:nil];
而
[self.view removeFromSuperview];
它的作用是将当前视图从其父视图中移除。在一个viewcontroller中view为当前视图的base视图,如果将它移除会显示UIWindow的默认背景色,也就是你看到的黑色屏幕