- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
作为“年轻的 iOS padawan”,我有以下愚蠢的问题要问 -
在 Xcode 5 中我创建了 an iPhone app与 storyboard (包含管理其他 3 个 View Controller 的导航 Controller )和 AppDelegate.m 中的以下代码:
- (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/
我是一名优秀的程序员,十分优秀!