[英]ELCImagePickerController does not back to viewController in swift
我使用ELCImagePickerController
選擇多張照片。 但是,當我選擇照片並單擊“完成”按鈕時,它會返回以選擇相冊頁面。 請幫幫我,所以當我選擇照片時,它應該回到viewController
。
這是我使用的代碼:
var picker = ELCImagePickerController(imagePicker: ())
@IBAction func ButtonIsclick(sender: AnyObject) {
picker.delegate = self
self.presentViewController(picker, animated: true, completion: nil)
}
func elcImagePickerController(picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info:[AnyObject]!) {
self.dismissViewControllerAnimated(true, completion: nil)
}
func elcImagePickerControllerDidCancel(picker: ELCImagePickerController!){
self.dismissViewControllerAnimated(true, completion: nil)
}
編輯 :當我調試代碼時,它永遠不會調用didFinishPickingMediaWithInfo
函數
實際上,由於錯誤地設置了delegate
我面臨着這個問題。
在我的問題中,我將delegate
設置為
picker.delegate = self
這是錯的。 正確的方法是將ELCImagepickerDelegate
設置為
picker.imagePickerDelegate = self
我已解決-在完整的最終工作代碼下方找到-
問題是我必須將ELCimagepickerdelegate添加到該類中,如下所示:
class ViewController: UIViewController, UINavigationControllerDelegate, ELCImagePickerControllerDelegate {
但是,我每次這樣做都會得到一個錯誤(類型viewcontroller不符合協議),因此解決方案是忽略此錯誤,直到我在代碼中添加下面的2個委托方法(該錯誤停止了,這非常令人困惑-對不起,我是新手,感謝大家的幫助
整個工作代碼:
import UIKit
import ELCImagePickerController
class ViewController: UIViewController, UINavigationControllerDelegate, ELCImagePickerControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var picker = ELCImagePickerController()
@IBAction func OpenPhotos(_ sender: AnyObject) {
picker.imagePickerDelegate = self
self.present(picker, animated: true, completion: nil)
}
func elcImagePickerController(_ picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [Any]!) {
dismiss(animated: true, completion: nil)
}
func elcImagePickerControllerDidCancel(_ picker: ELCImagePickerController!) {
dismiss(animated: true, completion: nil)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.