我遇到了问题,我不知道如何解决它。这就是我尝试做的事情:用户从他的iphone上的专辑中挑选一张图片。当图像将保存在应用程序文件夹中时,应弹出一个操作表,其上有一个活动指示器,直到保存过程完成。下面你可以看到我是如何尝试的,但我认为我的代码会导致内存问题(EXC_BAD_ACCESS),但我无法修复它。
当我调试时,我发现,下面列出的两种方法都会在一个循环中被调用,这就是让我最困惑的。
提前感谢您的帮助。
肖恩
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage* img = [info objectForKey:UIImagePickerControllerOriginalImage];
img = [self rotateImage:img byOrientationFlag:img.imageOrientation];
NSMutableArray *args = [[NSMutableArray alloc] init];
activityLoadImage = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(-17.5, -11, 35, 35)];
activityLoadImage.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
activityLoadImage.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
actionSheetLoadImage = [[UIActionSheet alloc] initWithTitle:@""
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
actionSheetLoadImage.actionSheetStyle = UIBarStyleBlackOpaque;
[actionSheetLoadImage setMessage:NSLocalizedString(@"_LoadImage", @"loading image")];
[actionSheetLoadImage addSubview:activityLoadImage];
[actionSheetLoadImage showInView:self.view];
[actionSheetLoadImage setBounds:CGRectMake(0,-105,320,720)];
[args insertObject:picker atIndex:0];
[args insertObject:img atIndex:1];
[args insertObject:[info objectForKey:UIImagePickerControllerOriginalImage] atIndex:2];
[activityLoadImage performSelectorOnMainThread:@selector(startAnimating) withObject:nil waitUntilDone:NO];
[self performSelector:@selector(saveImage:) withObject:args afterDelay:0.1];
[args release];
}
- (void)saveImage:(NSMutableArray *)arguments
{
UIImagePickerController *picker = [[arguments objectAtIndex:0] retain];
UIImage *img = [[arguments objectAtIndex:1] retain];
UIImage *orgImg = [[arguments objectAtIndex:2] retain];
// writes the image to specific location with the given file name
NSData *imageData = [self getImageData:img];
[imageData writeToFile:[self getImagePath] atomically:YES];
// writes the small image to specific location with the given file name
imageData = [self getSmallImageData:img];
[imageData writeToFile:[self getSmallImagePath] atomically:YES];
// sets UIImage for the UIImageView
[self setViewInfo];
lblNoImage.hidden = TRUE;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[self.tableView reloadData];
[activityLoadImage performSelectorOnMainThread:@selector(stopAnimating) withObject:nil wait UntilDone:NO];
[actionSheetLoadImage dismissWithClickedButtonIndex:0 animated:YES];
[activityLoadImage release];
[actionSheetLoadImage release];
}
答案 0 :(得分:0)
您将args传递给saveImage然后释放它。由于该方法在执行之前等待0.1秒,因此args已经被释放。尝试不释放args以查看是否可以解决您的问题,然后考虑更好的方法来管理内存,可能将其保留为类的属性。