这是我的代码:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing=YES;
[self presentViewController:picker animated:YES completion:nil];
}
PS:"sourceType = UIImagePickerControllerSourceTypePhotoLibrary "
没关系。
"sourceType = UIImagePickerControllerSourceTypeCamera "
这是错的。
这是我得到的错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x21f1949f 0x2f700c8b 0x21e39873 0x21e39657 0x2544bbc3 0x2544b815 0x253e4d67 0x2aa06681 0x253d924f 0x24e01a0d 0x24dfd3e5 0x253eb987 0x26bd5fa5 0x26bd13b3 0x26bd2429 0x26bcbad9 0x2aa03cb5 0x2a9d1b53 0x253f151b 0x2548528f 0x25484d63 0x256cba3f 0x256caf87 0x254f92cf 0x256ca81f 0x256bc6df 0x254f919d 0x2561fb1b 0x2561f9f3 0x253f151b 0x256a7c8d 0x25455a25 0x253d182b 0x21edfd95 0x21edd453 0x21edd85b 0x21e2b3c1 0x21e2b1d3 0x291e90a9 0x2543afa1 0x1d1a65 0x2fc80aaf)
我可以帮忙解决这个问题吗?
答案 0 :(得分:1)
-(void)actionLaunchAppCamera
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentModalViewController:imagePicker animated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Camera Unavailable"
message:@"Unable to find a camera on your device."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
alert = nil;
}
}