iOS - UITableView崩溃
问题描述:
我有图像加载到UITableViewCell中。图像尺寸不是很大 - 每个图像大概只有6 KB。iOS - UITableView崩溃
但是有500行。当我滚动时,它首先开始慢,给我的内存警告消息,但后几个滚动,应用程序崩溃。我也使用过仪器,它显示出我滚动时内存使用量越来越高!难道dequeueReusableCellWithIdentifier:CellIdentifier
工作不正常,或者我应该以某种方式'无'的图像?!
顺便说一句,我已经关闭了设备上的所有其他应用程序,并且我的iPod Touch上有超过1.5 GB的免费空间。
下面是配置单元代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
int cellNumber = indexPath.row + 1;
NSString *cellImage1 = [NSString stringWithFormat:@"c%i.png", cellNumber];
UIImage *theImage = [UIImage imageNamed:cellImage1];
[cell.imageView setImage:theImage];
return cell;
}
答
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
UITableViewCell *cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
这是怎么回事?你重新分配两次相同的内存。
//我正在使用ARC(自动引用计数)。 我重新启动了该设备,崩溃有点问题得到解决。但内存使用率仍然变高(仪器显示它) – Milad 2012-07-06 10:30:13