gpt4 book ai didi

ios - 是否实例化ViewControllerWithIdentifier : create a copy of the VC or will the storyboard one be magically not created

转载 作者:行者123 更新时间:2023-11-29 12:53:45 26 4
gpt4 key购买 nike

作为“年轻的 iOS padawan”,我有以下愚蠢的问题要问 -

在 Xcode 5 中我创建了 an iPhone appstoryboard (包含管理其他 3 个 View Controller 的导航 Controller )和 AppDelegate.m 中的以下代码:

Storyboard screenshot

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc1 = [storyboard instantiateViewControllerWithIdentifier:@"Master"];
//UIViewController *vc2 = [storyboard instantiateViewControllerWithIdentifier:@"Login"];
UIViewController *vc3 = [storyboard instantiateViewControllerWithIdentifier:@"User"];

User *user = [User load];
NSArray *controllers = (user ? @[vc1, vc3] : @[vc1]);

UINavigationController *nc = (UINavigationController *)self.window.rootViewController;
[nc setViewControllers:controllers];

return YES;
}

我的问题是:因为 self.window.rootViewController 在上面的代码中使用,这意味着 Main.storyboard 文件已经被应用程序加载并且“卡住”在其中的 VC 已经被实例化了,对吧?

这是否意味着,当我调用 instantiateViewControllerWithIdentifier ,然后创建每个 VC 的第二个副本

当我稍后在我的应用程序源代码中设置/更改 VC 的属性时, Storyboard管理的 VC 不受影响(但仍向用户显示)?

最佳答案

the Main.storyboard file has already been loaded by the app

when I call instantiateViewControllerWithIdentifier, then a second copy of each VC is created

是的,如果 View Controller 在根导航 Controller 内,否则否(因为应用程序应该还没有理由加载它们)。所以,对于主视图 Controller 来说是的,对于用户 View Controller 来说不是。

set/change a property on a VC later

这真的取决于代码

Storyboard是一个容器,用您的话说,是“卡住的”(真正归档的) View Controller 和 View 。您的代码不会更改 Storyboard的内容,它只是在不同的时间根据不同的触发器加载存档的不同部分。从 Storyboard存档创建这些元素后,您可以修改它们,但这是基于您的代码的运行时修改。

关于ios - 是否实例化ViewControllerWithIdentifier : create a copy of the VC or will the storyboard one be magically not created,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21679828/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com