我有一个打开相机应用程序的按钮,以便用户可以将其保存为 UIImage。我收到使用未声明的标识符错误,但我不知道为什么。任何帮助,将不胜感激。
#pragma mark - Camera Button
- (IBAction)cameraButton:(id)sender {
[self startCameraControllerFromViewController:self usingDelegate:self];
}
#pragma mark - Save picture callbacks
- (void) image:(UIImage *) image didFinishSavingWithError:(NSError *)error contextInfo:(void *) contextInfo {
if(error) {
#pragma mark - Get picture by taking picture
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller usingDelegate: (id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera] == NO) || (delegate == nil) || (controller == nil))
return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.delegate = delegate;
[controller presentViewController:cameraUI animated:YES completion:nil];
return YES;
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage * image = info[UIImagePickerControllerOriginalImage];
_label.text = [NSString stringWithFormat:@"Have image: %d x %d", (int) image.size.width, (int) image.size.height];
_imageView.image = image;
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
}
@end
最佳答案
看起来只是一个语法错误:
- (void) image:(UIImage *) image didFinishSavingWithError:(NSError *)error contextInfo:(void *) contextInfo {
if(error) {
#pragma mark - Get picture by taking picture
永远不要关闭 if 语句两边的大括号。
将其更改为:
- (void) image:(UIImage *) image didFinishSavingWithError:(NSError *)error contextInfo:(void *) contextInfo {
if(error) {
NSLog(@"Error saving image: %@", error);
}
}
#pragma mark - Get picture by taking picture
关于ios - 使用未声明的标识符 'startCameraControllerFromViewController',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25224341/