2013-07-11 66 views
0

因此,在我選擇圖像後,我的iPhone 4設備中圖像選擇器彈出消失。這部作品在iPhone 4,但下面的代碼不會爲iPhone 5dismissModelViewControllerAnimated不適用於iPhone 5

- (void) loadImage:(UIImage*) image { 
float w = image.size.width; 
float h = image.size.height; 
float maxw = scrollView.frame.size.width; 
float maxh = scrollView.frame.size.height; 
float wratio = maxw/w; 
float hratio = maxh/h; 
float ratio = wratio < hratio ? wratio : hratio; 
ratio = ratio < 1 ? ratio : 1; 

int adjW = (int) (w * ratio); 
int adjH = (int) (h * ratio); 

UIGraphicsBeginImageContext(CGSizeMake(adjW, adjH)); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
[image drawInRect:CGRectMake(0, 0, adjW, adjH)]; 

CGImageRef scaledImage = CGBitmapContextCreateImage(context); 

UIGraphicsEndImageContext(); 

[appDelegate.model setCurrentImage:[UIImage imageWithCGImage: scaledImage]]; 
[self clear]; 
calcButton.enabled = YES; 
trashButton.enabled = YES; 
scribbleControls.enabled = YES; 
[appDelegate.mergeViewCtlr setFirst]; 
} 

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
[self loadImage:[info objectForKey:UIImagePickerControllerOriginalImage]]; 

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    if ([popoverController isPopoverVisible]) { 
     // called for iPad 
     [popoverController dismissPopoverAnimated:YES]; 
    } 
} 
else { 
    // called for iPhone and tried each of the next 3 lines individually 
    [self dismissModalViewControllerAnimated:YES]; <== NOT WORKING 
    [self dismissViewControllerAnimated:YES completion:nil]; <== ALSO NOT WORKING 
    [picker dismissViewControllerAnimated:YES completion:nil]; <== ALSO NOT WORKING 
} 

[picker release]; 
} 

我也注意到,它說dimissModelViewControllerAnimated已被棄用,而不是說我應該使用工作: 使用dismissViewControllerAnimated:完成:代替。但是,我會如何使用它?由於

這裏呈現的模型視圖代碼: - (空)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger的)buttonIndex {

switch (buttonIndex) { 
    case 0: { //photo library 
     if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { 
      UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
      imagePicker.delegate = self; 
      imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
       if ([popoverController isPopoverVisible]) { 
        [popoverController dismissPopoverAnimated:YES]; 
       } 
       else { 
        popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 
        popoverController.delegate = self; 
        [popoverController presentPopoverFromRect:CGRectMake(250, -50, 320, 480) 
                 inView:[self view] 
            permittedArrowDirections:UIPopoverArrowDirectionUp 
                animated:YES]; 
       } 
      } 
      else { // for iPhone 
       [self presentModalViewController:imagePicker animated:TRUE]; 
      } 
     } else { 
      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Photo library is empty or unavailable" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alertView show]; 
     } 
     break; 
    } 
    case 1: //camera 
+0

你確定你的其他區塊正在進入嗎?你是否設置了一個斷點以確保它是?如果是這樣,那麼你應該嘗試在picker上調用dismissViewControllerAnimated:completion:方法,而不是self。 – JiuJitsuCoder

+0

我確定它正在進入,因爲我在那裏有我在上面省略的打印語句。我試過[picker dismissViewControllerAnimated:YES completion:nil];但它也不起作用。謝謝! –

回答

1
[self dismissViewControllerAnimated:YES completion:nil]; 

presentModalViewController,並dismissModalViewController depracated在iOS6

2

dismissModalViewControllerAnimated::deprecated in iOS6。改爲使用dismissViewControllerAnimated:completion:

+0

但我該如何使用它? –

+0

你能展示你用來展示模態視圖的代碼嗎? – Anthony

+0

我已經添加了,謝謝你回來! –

0

試試這個,

[self.imagePicker dismissViewControllerAnimated:NO completion:nil]; 

,並使用

[self presentViewController:self.picker animated:YES completion:nil]; 

您還可以使用respondsToSelector,使案件的iOS 5和iOS6的。

相關問題