ios - 您将如何以及在何处使用 instantiateViewControllerWithIdentifier

标签 ios iphone ios5 ios4 uistoryboard

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/

相关文章:

ios - 将 paypal 访问与 ios 应用程序集成

ios - Swift (iOS) 插件 - 插件错误中未定义方法 - Cordova

ios - 使用 CoreBluetooth 检测 Apple Watch

iphone - 进入/退出编辑模式时重绘 UITableViewCell

iphone - OpenGL ES 2.0 在 iPhone 模拟器中显示正常,但在 iPhone 上显示不佳

ios - 将数据从一个 View 传递到另一个 View (Storyboard,iOS)

iphone - strncpy 对 iPhone 开发安全吗?

iphone - 如何从 iOS 应用程序 ping 服务器?

iphone - UITableView 部分标题 iOS 5

opengl-es - 使用 CVPixelBufferRef 和 Shaders 在 ffmpeg 的 OpenGL 中渲染 YUV 视频