0

질문이 있습니다. 내 응용 프로그램에 2 개의 단추가있는 UIActionSheet가 있는데 사진을 찍고 라이브러리에서 사진을 선택합니다. 내 질문은 장치가 카메라를 사용할 수 있는지 여부를 확인하는 방법입니다. 어떻게하면 작업 시트에서 사진 찍기 버튼을 비활성화 할 수 있습니까? 많은 것을 시도했지만 나에게 도움이되지 않았습니다. 아래 코드를 추가하고 있습니다. 제 코드에 어떤 문제가 있는지 알려주세요. 사진 촬영 버튼을 비활성화로 설정하면 "인식 할 수없는 선택기를 보냈습니다"라는 오류 메시지가 나타납니다.장치에 카메라가 객관적인 -C가없는 경우 UIActionSheet 카메라 단추를 비활성화하는 방법

-(void)gestureRecognizer { 
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TapOnImage)]; 
[recognizer setNumberOfTapsRequired:2]; 
recognizer.cancelsTouchesInView = NO; 
[self.employeeImage addGestureRecognizer:recognizer]; 
self.employeeImage.userInteractionEnabled = YES; 
} 

-(void)TapOnImage { 
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"" delegate:self cancelButtonTitle:@"" destructiveButtonTitle:nil otherButtonTitles:@"Take photo",@"Choose photo", nil]; 
actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic; 

// NSString *model = [[UIDevice currentDevice]model]; 
// NSLog(@"current device:%@",model); 

// if([model isEqualToString:@"iPad1,1"]) { 
// NSString *button = (NSString *)[actionSheet buttonTitleAtIndex:0]; 
// 
//   UIButton *btn = (UIButton *)button; 
//   if ([[btn currentTitle] isEqualToString:@"Take photo"]) { 
//    // Do things with button. 
//    button.hidden = YES; 
//   } 

// } 


[actionSheet showFromRect:self.employeeImage.frame inView:self.view animated:YES]; 

} 

- (void)displayImagePicker:(UIImagePickerController *)imagePicker { 
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    // present from popover 
    self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 

    [self.popover presentPopoverFromRect:self.employeeImage.frame//popOverRect 
            inView:self.view 
       permittedArrowDirections:UIPopoverArrowDirectionLeft 
           animated:YES]; 
} else { 
    [self presentModalViewController:imagePicker animated:YES]; 
} 
} 

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex { 
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
imagePicker.delegate = self; 
imagePicker.allowsEditing = YES; 

if(buttonIndex == 0) { 
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 
     imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    } 
else { 
     UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Sorry" message:@"This device doesn't support camera" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles: nil]; 
     [alert show]; 

    } 
    return; 
} 
else if(buttonIndex == 1) { 
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { 
     imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    } 
    else { 
     return; 
    } 
} 
else { 
    return; 

} 

[self displayImagePicker:imagePicker]; 
} 

답변

2

사용이 카메라를 사용할 수 있는지 확인하거나 답장을하지

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; 
+0

감사합니다. 하지만 카메라가 없다면 액션 시트 버튼을 비활성화해야합니다. 가능합니까? – jessy

+0

나는이 문제를 해결할 수 있었다 :) – jessy