0

我得到了这个 uiactionsheet,它在 UISplitViewController 中的 viewcontroller 中加载了 uipickerviewcontroller

这是一个UIsplitviewcontroller,这段代码在detailview上,detailview是从masterview调用的

然而,当我尝试加载它时“点击它”它给了我一个警告并且没有进一步

   func actionSheet(actionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int){
    var imagePicker = UIImagePickerController()
    imagePicker.delegate = self

    switch buttonIndex{

    case 0:
        imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        imagePicker.allowsEditing = true
        imagePicker.delegate = self
        NSLog("Vælg fra Biblioteket");
        break;
    case 1:
        imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
        imagePicker.allowsEditing = true
        imagePicker.delegate = self
        NSLog("Vælg Kamera");
        break;
    default:
        NSLog("Default");
        break;
    }
    self.presentViewController(imagePicker, animated: true, completion: nil) // this is the problem 
}

警告是这样的:警告:尝试呈现已经呈现的(空)

如果我使用这个: self.showDeatilViewController(imagePicker, true) 它会出现但我根本无法关闭它

这就是我认为它会被解雇的方式

    func imagePickerControllerDidCancel(picker: UIImagePickerController) {

    picker.dismissViewControllerAnimated(true, completion: nil)
}

如果我在 viewDidLoad 中运行此代码,它可以工作

        var imagePickerController = UIImagePickerController()
    imagePickerController.delegate = self
    imagePickerController.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
    imagePickerController.allowsEditing = true
    self.presentViewController(imagePickerController, animated: true, completion: { imageP in

    })

我发现如果我写这个:

        self.presentedViewController?.presentViewController(imagePicker, animated: true, completion: nil)

它显示并关闭?!?!

4

1 回答 1

4

我已经开始工作了...有人提请我注意 8.0 IOS 存在从应用程序打开 photolibery 等的错误.. 所以我像这样将它放在主队列中

dispatch_async(dispatch_get_main_queue()){
        imagePicker.delegate = self
        self.presentViewController(imagePicker, animated: true, completion: nil)
    }

现在它可以工作了!

一点延迟,但它有效

于 2014-10-04T08:03:51.390 回答