【发布时间】:2012-11-24 22:57:23
【问题描述】:
我在我的 iOS6 / iOS6 应用程序中将多个故事板与 NIB 文件混合在一起。
内存管理如何与多个故事板一起使用?
- 启动 storyboardA 后,如果我返回到另一个 nib 文件/转到另一个 storyboard,那个 storyboardA 会留在内存中吗?
- 我能否像使用 UIViewControllers 获取导航控制器堆栈中的视图数组一样堆栈中的情节提要“数组”?
- 对于内存管理,我可以从内存中弹出或删除情节提要吗?当我转到另一个故事板时,是否将其设置为 nil?
我使用多个故事板与 nib 文件混合使用的原因:
- 我想要复杂的叙事故事板流程。将它们全部放在一个地方是没有意义的。
- 最终我将与许多不同的人一起工作,我发现团队合作、版本控制的论据足以让我选择多故事板路线
- 我正在混合 NIB 文件,因为情节提要尚无法处理复杂的 nib 文件、许多编程视图等。
我的代码片段
InitialNibFile.m
- (IBAction)newStoryboardBtnPressed:(id)sender {
[self.view removeFromSuperview]; // here I remove this view from the superview to save memory
UIStoryboard *newStoryboard = [UIStoryboard storyboardWithName:@"NewStoryboard" bundle:nil];
UIViewController *initialSettingsVC = [newStoryboard instantiateInitialViewController];
[self presentViewController:initialSettingsVC
animated:YES completion:nil];
}
这里, 在故事板场景中的 UIViewController 视图中。
- (IBAction)anotherStoryboardBtnPressed:(id)sender {
// I'm inside a storyboard right now. I'm calling another storyboard.
// can i remove this storyboard before i launch the otherone? will keeping 2 or 3 toryboards in memory cause a memory leak?
UIStoryboard *settingsStoryboard = [UIStoryboard storyboardWithName:@"AnotherStoryboard" bundle:nil];
UIViewController *initialSettingsVC = [settingsStoryboard instantiateInitialViewController];
// i'm going to load this view controller modally
// initialSettingsVC.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentViewController:initialSettingsVC
animated:YES
completion:nil];
}
【问题讨论】:
标签: iphone memory-management ios6 uistoryboard