当我加载带有缩略图的配置文件时,我的应用程序崩溃了UITableView
。
它可以正确加载多达 5 个带有图片的配置文件。但是,当我创建第六个时,然后在带有图片的表格视图中加载配置文件时它会崩溃,向我显示内存警告消息。
其实我用过ARC
。所以,我无法释放内存。我只能使用autoreleasepool
来释放内存。
下面是我用来加载UITableView
带有个人资料图片的个人资料的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
@autoreleasepool
{
static NSString *CellIdentifier=@"Cell";
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
}
MyProfile * objMP1 = [GlobalgroupedProfileArray objectAtIndex:[indexPath row]];
NSString *titleText =[@"Name: " stringByAppendingString:objMP1.Name];
cell.textLabel.text=titleText;
NSString *strTitle1=[@"Owner: "stringByAppendingString:[objMP1.Owner stringByAppendingString:@"\n"]];
NSString *strTitle2=[@"Breed: "stringByAppendingString:[objMP1.Breed stringByAppendingString:@"\n"]];
NSString *strTitle=[[strTitle1 stringByAppendingString:strTitle2] stringByAppendingString:[@"ID Number: "stringByAppendingString:[NSString stringWithFormat:@"%@",objMP1.IDNumber]]];
cell.detailTextLabel.text=strTitle;
cell.detailTextLabel.numberOfLines =3;
@autoreleasepool
{
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(cell.frame.size.width-70-25, 15, 50, 50)];
imageView.image = objMP1.img;
[cell addSubview:imageView];
imageView=nil;
}
@autoreleasepool
{
// Load the image with an GCD block executed in another thread
dispatch_queue_t downloadQueue = dispatch_queue_create("image downloader", NULL);
dispatch_async(downloadQueue, ^{
CGSize newSize = CGSizeMake(50, 50); //whaterver size
UIGraphicsBeginImageContext(newSize);
[objMP1.img drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_async(dispatch_get_main_queue(), ^{
@autoreleasepool
{
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(cell.frame.size.width-70-25, 15, 50, 50)];
imageView.image = newImage;
[cell addSubview:imageView];
imageView=nil;
}
});
});
dispatch_release(downloadQueue);
}
[cell.imageView setImage:newImage];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
}
任何提示?