Rom*_*ano 5 iphone memory-management uistoryboard ios6
我在iOS6/iOS6应用程序中混合了多个故事板和NIB文件.
内存管理如何与多个故事板一起使用?
我使用多个与nib文件混合的故事板的原因:
我的代码片段
在InitialNibFile.m里面 - 从appdelegate启动.
- (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];
}
Run Code Online (Sandbox Code Playgroud)
这里,在故事板场景中的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];
}
Run Code Online (Sandbox Code Playgroud)
所以这里我们去=)
在启动storyboardA时,如果我返回到另一个nib文件/转到另一个故事板,那个故事板是否会留在内存中?
故事板由您创建(通过storyboard)属性的UIViewController保留.所以是的,它确实留在内存中,直到它的所有视图控制器都被释放.查看(简要)文档.
我是否能够在堆栈中获得故事板的"数组",这样我就可以使用UIViewControllers在导航控制器的堆栈中获取视图数组?
不,因为故事板彼此独立.但是,您可以通过迭代导航堆栈中的视图控制器来获取故事板.
对于内存管理,我可以从内存中弹出或删除故事板吗?当我去另一个故事板时,我将它设置为零吗?
只要你在内存中有一个实例化的视图控制器,它就会保持不变.当您使用storyboardWithName:自动释放的对象时,会返回给您.视图控制器将保留它,因此不必担心释放或设置为nil.
对于你的其他问题的参考,我推荐到SO和其他互联网:
SO
UIStoryboard 上的故事板最佳实践最佳实践
iOS上的多个故事板SO
快乐的故事板.