【问题标题】:Can't dismiss UIImagePickerController无法关闭 UIImagePickerController
【发布时间】:2014-08-26 03:17:22
【问题描述】:

编辑:我刚刚发现问题是 UIImagePicker 而不是视频编辑器更改代码来表示它。

我正在努力做到这一点,所以当他们点击 UIImagepicker 上的取消按钮时,它会关闭它并退出 Facebook 并转到主视图。

这是我必须忽略的。

    -(IBAction)Logout:(id)sender
{
    [[FBSession activeSession]closeAndClearTokenInformation ];
    [self.parentViewController dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popToRootViewControllerAnimated:(YES)];
}

这是我展示图像选择器的方式

//Create an image picker
    UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    //Get the videos from the photo library
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    //Set media types to movie tyeps
    imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *) kUTTypeMovie, nil];
    //present the controller

    [self presentViewController:imagePicker animated:YES completion:nil];

我得到的错误是由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'* -[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'

我什至没有在我的程序中的任何地方使用 initFileURLWithPath,所以我不知道现在的问题是什么。我已经缩小范围,认为解雇导致错误发生,我不确定现在出了什么问题。谢谢。

【问题讨论】:

  • 我设法解决了这个问题。错误的代码不是发布的代码的一部分。基本上我试图将一个 url(那是 nil)分配给另一个 url,这就是导致错误的原因。错误消息仍然有点模棱两可。

标签: ios objective-c


【解决方案1】:

在您的 viewController 的头文件中,您应该已经实现了以下委托

@interface ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

这将允许您访问 UIImagePickerController 的委托方法,一旦按下 UIImagePicker 取消按钮就会触发。其中一种方法是didFinishPickingMediaWithInfo 下面的一种。您需要添加此方法并从此处关闭选择器。

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

//Within this method you can capture/save etc the media you have just recorded etc too.

//Use the line below to dismiss the pickerController

    [picker dismissViewControllerAnimated:YES completion:nil];

}

希望对你有帮助

【讨论】:

  • 这些我都有。我应该将它包含在我的代码中,但是我在我的代码中得到了所有这些。问题是当用户点击取消按钮并点击关闭时,它会因我上面发布的错误而中断。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-02
  • 2019-10-07
相关资源
最近更新 更多