gpt4 book ai didi

ios - 如何显示 View Controller : UIImagePickController and dismiss it (Swift)

转载 作者:行者123 更新时间:2023-11-28 10:25:47 25 4
gpt4 key购买 nike

我得到了这个加载 uipickerviewcontroller 的 uiactionsheet它在 UISplitViewController 中的 View Controller 中

它是一个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)

它显示并关闭 ?!?!

最佳答案

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

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

现在可以了!

稍有延迟但有效

关于ios - 如何显示 View Controller : UIImagePickController and dismiss it (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26135866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com