0

我正在尝试使用“下一步”按钮制作一个 ViewController,该按钮将我带到同一个 ViewController 类的实例。

@interface ViewControllerDeco ()
{
    ViewControllerDeco *page1;
}

viewDidLoad:

page1 = [[ViewControllerDeco alloc]init];

按钮:

- (IBAction)btnNext:(id)sender {
    [self.navigationController pushViewController:page1 animated:YES];
}

它显示黑屏,我错过了什么吗?

4

2 回答 2

1

因此,如果您没有在 ViewControllerDeco 控制器初始化函数中添加 UI 元素,则会出现黑屏。如果您想基于情节提要中的视图控制器创建 ViewControllerDeco 的实例,请尝试以下操作:

ViewControllerDeco *page1 = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerDeco"];
[self.navigationController pushViewController:page1 animated:YES];

确保将情节提要标识符添加到要在代码中加载的 VC。

于 2013-10-21T19:59:23.247 回答
0

initiating view controller with

page1 = [[ViewControllerDeco alloc]init];

doesn't actually get it from storyboard, it just creates empty new one (which one you can set up in viewDidLoad for example), if you want to create that one from storyboard, you should do something like:

UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerDecoId"];
[self.navigationController pushViewController:vc animated:YES];

previously you should set "ViewControllerDecoId" to "Storyboard id" of your controller in your storyboard

hope helped

于 2013-10-21T19:57:39.460 回答