[ios]跳转页面黑屏解决

Xcode的Storyboard用连线跳转界面非常方便,但是有时候直接连线不能解决所需要的问题,直接用presentViewController方法跳转Storyboard中的VC会导致黑屏。

原因:Storyboard在创建第二个视图对应的类时系统自动重写了-(void)viewDidLoad这个方法,而presentViewController这个方法是不允许重写-(void)viewDidLoad这个方法。

于是就把系统自动生成的ViewController2类的内容全删了。

解决方案(1):

利用storyboard的identifier跳转:

设置第二个界面的storyboard ID为vc2

第一个vc中btn按钮的代码:

UIStoryboard *storboard = self.storyboard;
ViewController2 *vc2 = [storboard instantiateViewControllerWithIdentifier:@"vc2"];
[self presentViewController:vc2 animated:YES completion:nil];
or
[self.navigationController pushViewController:vc2 animated:YES];

解决方案(2)在vc2的viewDidLoad中添加视图、控件

相关推荐