2014-01-07 36 views
0

我會用相機創建一個應用程序,但是當我在ImageViewController.m中編寫這段代碼時 xcode:預期的METODY BODY和「。」 我該如何解決這個問題? 謝謝相機imagepicker程序中的iOS錯誤

-(BOOL) launchCameraControllerFromViewController: (UIViewController*) controller usingDelegate: (id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>) 
      BOOL truefalse = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; //variable to check whether there is a camera available 
      //if there is a camera, the delegate passed exists, and the controller passed exists, proceed on, otherwise don't go any further 
      if (!truefalse || (delegate == nil) || (controller == nil)) { 
       NSLog(@"no can do, delegate/camera/view controller doesn't exist!"); 
       return NO; 
      } 

      UIImagePickerController *cameraController = [[UIImagePickerController alloc] init]; 

      cameraController.sourceType = UIImagePickerControllerSourceTypeCamera; 
      cameraController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; 
      cameraController.allowsEditing = NO; 
      cameraController.delegate = delegate; 
+0

您是否有方法體的結束標記? –

回答

0

它說你根本沒有辦法。嘗試更改爲此(請注意方法名稱和所有代碼後的大括號):

-(BOOL) launchCameraControllerFromViewController: (UIViewController*) controller usingDelegate: (id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>) delegate{ 
      BOOL truefalse = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; //variable to check whether there is a camera available 
      //if there is a camera, the delegate passed exists, and the controller passed exists, proceed on, otherwise don't go any further 
      if (!truefalse || (delegate == nil) || (controller == nil)) { 
       NSLog(@"no can do, delegate/camera/view controller doesn't exist!"); 
       return NO; 
      } 

     UIImagePickerController *cameraController = [[UIImagePickerController alloc] init]; 


      cameraController.sourceType = UIImagePickerControllerSourceTypeCamera; 
      cameraController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; 
      cameraController.allowsEditing = NO; 
      cameraController.delegate = delegate; 

} 
0

你可以試試這個。

- (IBAction)presentPicker:(id)sender { 

    // ********************************************** 
    // * Show action sheet that will allow image selection from camera or gallery 
    // ********************************************** 
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:(id)self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Image from Camera", @"Image from Gallery", nil]; 
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent; 
    actionSheet.alpha=0.90; 
    actionSheet.tag = 1; 
    [actionSheet showInView:[UIApplication sharedApplication].keyWindow]; 

} 



    #pragma mark - Image picker methods 

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex { 
    switch (actionSheet.tag) { 
       case 1: 
       switch (buttonIndex) { 
       case 0: 
        [self showCameraImagePicker]; 
        break; 
       case 1: 
        [self showGalleryImagePicker]; 
        break; 
      } 
      break; 
      default: 
      break; 
    } 
} 


    - (void)showCameraImagePicker { 


       #if TARGET_IPHONE_SIMULATOR 
       UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Simulator" message:@"Camera not available." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show]; 
    #elif TARGET_OS_IPHONE 
     UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
     picker.delegate = self; 
     picker.allowsEditing = YES; 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
     [self presentViewController:picker animated:YES completion:NULL]; 
     // [(UIViewController *)self.delegate presentModalViewController:picker animated:YES]; 
     #endif 



    } 

    - (void)showGalleryImagePicker { 

     UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
     picker.delegate = self; 
     picker.allowsEditing = YES; 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

     [self presentViewController:picker animated:YES completion:NULL]; 

    // [(UIViewController *)self.delegate presentModalViewController:picker animated:YES]; 

     } 

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage: (UIImage *)image editingInfo:(NSDictionary *)editingInfo { 

    // [picker dismissModalViewControllerAnimated:NO]; 
     [picker dismissViewControllerAnimated:YES completion:NULL]; 

     photo.image = image; 

    //[self presentImageCropperWithImage:image]; 


    } 

    -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info { 

// [picker dismissModalViewControllerAnimated:NO]; 
    [picker dismissViewControllerAnimated:NO completion:nil]; 

    // Extract image from the picker 
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; 
    if ([mediaType isEqualToString:@"public.image"]){ 

     UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 

     photo.image = image; 

     [picker dismissViewControllerAnimated:YES completion:NULL]; 

     // [self presentImageCropperWithImage:image]; 
    } 
    } 


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 

    [picker dismissViewControllerAnimated:YES completion:NULL]; 

} 
相關問題