iPhone:在哪里为dataSource分配内存? [英] Iphone: Where allocate memory for dataSource?

查看:89
本文介绍了iPhone:在哪里为dataSource分配内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于填充UITableView的数组.

i have an array used to populate the UITableView.

问题是我应该在哪里分配内存.我在viewDidLoad或viewWillAppear中有两个选项,但是从内存管理的角度来看,我不知道哪里更有效.

The question is where i should to allocate memory for it. I have two options in viewDidLoad or viewWillAppear, but i don't know where is more efficient from the point of view of memory management.

谢谢

我创建视图的步骤如下:

I create the view doing the following:

NextViewController *nextController = [[ReservationsViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
nextController.managedObjectContext = self.managedObjectContext;
[self.navigationController pushViewController:nextController animated:YES];
[nextController release];

但是我不想每次显示都分配内存,只是第一次加载视图以便从内存管理的角度来看是正确的.

But i don't want to allocate memory every time is shown, only the first time the view is loaded in order to be right from the point of view of memory-management.

推荐答案

如果只希望分配一次,则应根据创建视图控制器的方式在init方法或awakeFromNib中分配它.

If you only want it to be allocated once then you should alloc it either in the init method or in awakeFromNib depending on how your view controller is created.

viewWillAppear可能会被多次调用,并且不能保证viewDidLoad仅被调用一次.

viewWillAppear will likely be called multiple times and viewDidLoad is not guaranteed to be called only once.

这篇关于iPhone:在哪里为dataSource分配内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆