[英]how to show viewcontroller: UIImagePickController and dismiss it (Swift)
我得到了這個uiactionsheet,它在UISplitViewController的viewcontroller中加載了uipickerviewcontroller
這是一個UIsplitviewcontroller,此代碼位於detailview上,從masterview調用detailview
但是,當我嘗試加載“單擊它”時,它會警告我並且不再繼續
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在打開應用程序的照片庫等時出現了一個錯誤。所以我將其放在這樣的主隊列中
dispatch_async(dispatch_get_main_queue()){
imagePicker.delegate = self
self.presentViewController(imagePicker, animated: true, completion: nil)
}
現在就可以了!
稍有延遲,但有效
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.