我得到了这个加载uipickerviewcontroller的uiactionsheet 它位于UISplitViewController
中的viewcontroller中它是一个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
}
警告是这样的:警告:尝试呈现已经呈现的(null)
如果我使用它: 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)
它显示并关闭?!?!
答案 0 :(得分:4)
我已经让它工作了...有人提醒我注意8.0 IOS有一个错误,打开photolibery等应用程序.. 所以我把它放在像这样的主队列中
dispatch_async(dispatch_get_main_queue()){
imagePicker.delegate = self
self.presentViewController(imagePicker, animated: true, completion: nil)
}
现在它有效!
稍微延迟但是有效