本文介绍了你如何以及在哪里使用instantiateViewControllerWithIdentifier的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                     bundle: nil];

MenuScreenViewController *controller = (MenuScreenViewController*)[mainStoryboard
                                               instantiateViewControllerWithIdentifier: @"<Controller ID>"];

如果我必须确保当前视图是使用标识?这意味着如果我在这个类上编写任何代码,它必须在这个viewcontroller加载时出现?我也将如何使用它?我不想创建menuscreenviewcontroller的实例。这意味着我必须说自己,但我使用self.view,但不起作用。

Where exactly do i write this code if i have to make sure that the current view is instantiated with the identifier? Which means if i write any code on this class it has to appear when this viewcontroller loads? Also how would i use it? I dont want to create an instance of the menuscreenviewcontroller. WHich means i have to say self but i used self.view and that doesnt work.

推荐答案

您需要推送或显示已创建的视图控制器。您无法通过实例化直接更改控制器的视图。

You need to push or present the view controller that you have created. You can not directly change views of the controllers by instantiating.

例如,您需要使用此代码来触发转换(可能是按钮操作):

For example you need to use this code to trigger the transition (maybe a button action):

MenuScreenViewController* controller = (MenuScreenViewController*)[ourStoryBoard instantiateViewControllerWithIdentifier:@"<Controller ID>"];

controller.controlFlag = YES;
controller.controlFlag2 = NO; // Just examples

//These flags will be set before the viewDidLoad of MenuScreenViewController
//Therefore any code you write before pushing or presenting the view will be present after

[self.navigationController pushViewController:controller animated:YES];
// or [self presentViewController:controller animated:YES];

这篇关于你如何以及在哪里使用instantiateViewControllerWithIdentifier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 10:33
查看更多