2012-08-25 8 views
0

iPhone 및 iPad 용 범용 앱이 있습니다. 아래 코드를 사용하여 사진 라이브러리 또는 카메라에서 사진을 가져 오려고합니다. 아이폰의 경우 잘 작동하지만 iPad의 경우 경고보기에서 아무 버튼이나 클릭해도 아무 것도 표시되지 않습니다. 문제는 무엇이 될 수 있습니까?UIPopoverController가 iPad에 표시되지 않습니다.

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { 

    if (buttonIndex == 0) { 
     UIImagePickerController* picker = [[UIImagePickerController alloc] init]; 
     picker.allowsEditing = YES; 
     picker.delegate = self; 
     camera = NO; 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

     [self presentModalViewController:picker animated:YES]; 


    } else if (buttonIndex == 1) { 

     BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; 
     camera = YES; 
     UIImagePickerController* picker = [[UIImagePickerController alloc] init]; 
     picker.allowsEditing = YES; 
     picker.delegate = self; 
     picker.sourceType = hasCamera ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary; 

     [self presentModalViewController:picker animated:YES]; 

     } 
    }else { 
    // We are using an iPad 
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 
    imagePickerController.delegate = self; 
    popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController]; 
    popoverController.delegate=self; 
    [popoverController presentPopoverFromRect:[self.view bounds] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
    } 

} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 

    if (clickedButton == YES) { 

      UIImage *originalImage, *editedImage; 

      editedImage = (UIImage *) [info objectForKey: UIImagePickerControllerEditedImage]; 

      originalImage = (UIImage *) [info objectForKey: UIImagePickerControllerOriginalImage]; 

      if (editedImage) { 

       thisImage = editedImage; 

      } else { 

       thisImage = originalImage; 

      } 

      imageThis.image = thisImage; 

     NSData *imageData = UIImageJPEGRepresentation(thisImage, 30); 

     [defaults setObject:imageData forKey:@"thisImage"]; 

     [defaults synchronize]; 

    // [[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(thisImage) forKey:@"thisImage"]; 

    } 
    else { 

     UIImage *originalImage, *editedImage; 

     editedImage = (UIImage *) [info objectForKey: UIImagePickerControllerEditedImage]; 

     originalImage = (UIImage *) [info objectForKey: UIImagePickerControllerOriginalImage]; 

     if (editedImage) { 

      thatImage = editedImage; 

     } else { 

      thatImage = originalImage; 

     } 

     imageThat.image = thatImage; 

     NSData *imageData = UIImageJPEGRepresentation(thatImage, 30); 

     [defaults setObject:imageData forKey:@"thatImage"]; 

     [defaults synchronize]; 

     //[[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(thatImage) forKey:@"thatImage"]; 

    } 

    [picker dismissModalViewControllerAnimated:YES]; 
} 

답변

0

그것은이 라인이다 :

당신은 컨트롤러의 시야 내에있는 사각형에서 제시해야
[popoverController presentPopoverFromRect:[self.view bounds] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

(나는 self 있으리라 믿고있어 뷰 컨트롤러), 그렇지 않으면 이상한 결과를 얻을 수 . 지금 테스트에서, 나는 popover 거절 하나를 나타 내기 위해 그 화살표의 끝 부분이 화면 중앙에 나타납니다. 예를 들면 다음과 같습니다.

[popoverController presentPopoverFromRect:[myButtonOutlet frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
0

이는 iPad에서 UIActionSheet를 사용했기 때문입니다. iPad에서는 UIActionSheet가 UIPopoverController를 사용하여 시트를 표시하고 UIActionSheetDelegate 메서드에서 UIActionsheet에서 사용하는 첫 번째 UIPopoverController가 숨겨져 있지 않을 때 다른 UIPopoverController를 사용합니다. 당신이 알아야 할 것은 언제든지 화면에 표시된 UIPopoverController 하나만있을 수 있다는 것입니다.

관련 문제