根据the documentation,instantiateViewControllerWithIdentifier
“每次调用时都会创建指定视图控制器的新实例。”
我正在使用Instruments的Activity Monitor运行我的应用程序(使用ARC),当我用来实例化之前实例化的ViewController时,我注意到内存使用量没有任何差别。
为什么?请参阅下面的方法goToPreviousPage
:
@implementation CBNavigator
int currentPage = 0;
-(IBAction)goToNextPage{
[self dismissViewControllerAnimated:YES completion:^{
currentPage++;
UIViewController *nextPageVC = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%d", currentPage ]];
[self presentModalViewController:nextPageVC animated:YES];
}];
}
-(IBAction)goToPreviousPage{
[self dismissViewControllerAnimated:YES completion:^{
currentPage--;
UIViewController *previousPageVC = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%d", currentPage ]];
[self presentModalViewController:previousPageVC animated:YES];
}];
}
@end