6つの画像ビューがあるビューがあります。カメラUIImagePickerControllerを使用して画像を設定しました。3番目の画像を選択するたびに、アプリが常にクラッシュし、機器をチェックしたときにリークはありません。どうしたの?これが私のコードです:
- (void)openCamera
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSData* imageData = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], 0.0001f);
[self dismissViewControllerAnimated:true completion:nil];
if ([_selectedButton isEqualToString:@"headOffice"])
{
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgHeadOffice"];
//_imgHeadOffice = [UIImage imageWithData:imageData];
_imgViewHeadOffice.image = [UIImage imageWithData:imageData];
}
else if ([_selectedButton isEqualToString:@"siteOffice"])
{
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgSiteOffice"];
//_imgSiteOffice = [UIImage imageWithData:imageData];
_imgViewSiteOffice.image = [UIImage imageWithData:imageData];
}
else if ([_selectedButton isEqualToString:@"roadCondition"])
{
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgRoadCondition"];
//_imgRoadCondition = [UIImage imageWithData:imageData];
_imgViewRoadCondition.image = [UIImage imageWithData:imageData];
}
else if ([_selectedButton isEqualToString:@"vehicle"])
{
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgVehicle"];
//_imgVehicle = [UIImage imageWithData:imageData];
_imgViewVehicle.image = [UIImage imageWithData:imageData];
}
else if ([_selectedButton isEqualToString:@"installedTire"])
{
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgInstalledTire"];
//_imgInstalledTire = [UIImage imageWithData:imageData];
_imgViewInstalledTire.image = [UIImage imageWithData:imageData];
}
else if ([_selectedButton isEqualToString:@"tireScrap"])
{
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imgTireScrap"];
//_imgTireScrap = [UIImage imageWithData:imageData];
_imgViewTireScrap.image = [UIImage imageWithData:imageData];
}
}
これが私のInstrumentsスナップショットです:
編集:アプリは処理ラインでクラッシュします
NSData* imageData = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], 0.0001f);
3回目は写真を撮ります。
これは、アプリを閉じたときのログです