这段代码在模拟器中运行良好,但每次在设备(iPhone 3GS)上崩溃,就在我拍照的时候。这段代码有问题吗?当我使用分配进行概要分析时,当它崩溃时活动内存只有 3-4 MB,所以看起来应用程序没有内存不足。我正在使用ARC。
-(IBAction)chooseImageNew:(UIButton*)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No Camera Available." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *img = [info objectForKey:@"UIImagePickerControllerEditedImage"];
self.userPicture.image = img;
[self.images replaceObjectAtIndex:0 withObject:img];
[self dismissModalViewControllerAnimated:YES];
}