2012-08-25 187 views
0

我擁有適用於iPhone和iPad的通用應用程序。使用下面的代碼我試圖從照片庫或相機中獲取圖片。對於iPhone的工作正常,但對於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是一個視圖控制器),否則你會有奇怪的結果。在剛剛進行的測試中,我有一個彈出窗口拒絕出現,一個箭頭出現在屏幕上。例如:

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

這是因爲您在iPad上使用UIActionSheet。在iPad上,UIActionSheet使用UIPopoverController呈現表單,並且在UIActionsSheetDelegate方法中,當UIActionsheet使用的第一個UIPopoverController尚未隱藏時,您使用另一個UIPopoverController。所有你需要知道的是,在任何時候只能有一個UIPopoverController顯示在屏幕上。