2014-05-19 64 views
0

我試圖駁回其上呈現如下辭退一個imagepickercontroller

[self.view.window.rootViewController presentViewController:imagePicker animated:YES completion:nil]; 

一個imagepickercontroller(相冊或攝像頭)通過調用:

 [self dismissViewControllerAnimated:YES completion:NULL]; 

我無法關閉imagepickercontroller。

任何機構都可以幫助我嗎?

+1

需要調用[** ** imagePicker dismissViewControllerAnimated:YES完成:無];在imagePickerController:didFinishPickingMediaWithInfo:或imagePickerControllerDidCancel :. – Jonathan

+0

這將是很好,如果你可以發佈這個作爲答案 –

回答

1

我用這個:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    [self dismissViewControllerAnimated:YES completion:nil]; 
else 
    [popover dismissPopoverAnimated:YES]; 

不知道NULL,而不是零是否重要,但它應該是零。

拾取器呈現以下代碼:

- (void)getVideoFromDevice 
{ 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // for ipad only 
    { 
     UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
     imagePicker.delegate = self; 
     imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
     imagePicker.allowsEditing = NO; 
     imagePicker.videoQuality = UIImagePickerControllerQualityTypeLow; 
     imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];; 
     popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 
     [popover presentPopoverFromBarButtonItem:[self.navigationItem.rightBarButtonItems objectAtIndex:0] permittedArrowDirections: UIPopoverArrowDirectionAny animated:YES]; 
    } 
    else // for iphone only - NOT TESTED 
    { 
     UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
     imagePicker.delegate = self; 
     imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
     [self presentViewController:imagePicker animated:YES completion:nil]; 
    } 
} 

我沒有測試iPhone的代碼還沒有,但iPad的部分是否正常工作。

+0

嗨,謝謝,但有一件事,popover從哪裏來? –

0

您需要關閉代表方法中的UIImagePickerViewControllerimagePickerController: didFinishPickingMediaWithInfo:imagePickerControllerDidCancel:。請務必將UIImagePickerViewController代表分配給代表UIImagePickerViewControllerUIViewController

實施例:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *) picker 
{ 
    [picker dismissViewControllerAnimated:YES completion:nil]; 
} 

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info 
{ 
    [picker dismissViewControllerAnimated:YES completion:nil]; 
}