1
私は別のViewControllerから画像を選択してセルフを取る必要があるアプリケーションで作業しています。私はこの目的のためだけにクラスを抽出したい。しかし、クラスの抽出後にdelegate
のメソッドUIPickerViewController
は呼び出されていません。swift:UIPickerViewControllerデリゲートはクラス抽出の後に呼び出されません
今、MultiMediaManager.swiftファイルにMultiMediaManager
というクラスがあります。
class MultiMediaManager: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
let imagePicker = UIImagePickerController()
var viewController: UIViewController?
var delegate: MultiMediaManagerDelegate?
init(presentingViewController: UIViewController) {
viewController = presentingViewController
super.init()
imagePicker.delegate = self
}
func showPictureSourceOptions() {
var presentationStyle: UIAlertControllerStyle = .ActionSheet
let galleryAction = UIAlertAction(title: "Photo Library", style: UIAlertActionStyle.Default) { (action) in
self.showPhotoGallery()
}
alertController.addAction(galleryAction)
self.viewController?.presentViewController(alertController, animated: true, completion: nil)
}
private func showPhotoGallery() {
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary
viewController?.presentViewController(imagePicker, animated: true, completion: nil)
// every thing is working till here as expected.
// note: here, debugger prints MultiMediaManager as imagePicker.delegate
}
ギャラリーから画像を選択して選択するビューが表示されます。しかし、私が画像を選択すると、viewcontrollerはただ静かに消して、その代理人は呼び出されません。
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
// break point does not stop here. nither print statement work.
viewController?.dismissViewControllerAnimated(true, completion: nil)
}
私は一日中頭を掻いていましたが、何が起こっているのかまだ分かりません。
'didFinishPickingMediaWithInfo'を追加した場所では、' MultiMediaManager'クラスの中に記述していないようです。 –
そのクラス内 – Ccr