UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
bundle: nil];
MenuScreenViewController *controller = (MenuScreenViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"<Controller ID>"];
如果我必须确保当前 View 是用标识符实例化的,我究竟应该在哪里编写这段代码?这意味着如果我在这个类上写任何代码,它必须在这个 viewcontroller 加载时出现?另外我将如何使用它?我不想创建 menuscreenviewcontroller 的实例。这意味着我不得不说 self 但我使用了 self.view 并且那不起作用。
最佳答案
您需要推送或呈现您创建的 View Controller 。您不能通过实例化直接更改 Controller 的 View 。
例如,您需要使用此代码来触发转换(可能是按钮操作):
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];
关于ios - 您将如何以及在何处使用 instantiateViewControllerWithIdentifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9666222/