我在一个应用程序上工作,这需要用户采取自拍图像从不同的ViewController。为了这个目的,我想提取类。但是在提取类之后,UIPickerViewController的delegate方法不会被调用。
现在,我在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
}将显示用于从图库中挑选图片的视图。但是当我选择图像时,视图控制器只是默默地不高兴,它的委托也不会被调用。
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
// break point does not stop here. nither print statement work.
viewController?.dismissViewControllerAnimated(true, completion: nil)
}我已经挠头一整天了,但我还是不知道发生了什么事。
发布于 2016-08-16 13:06:11
这些代码没有任何问题。问题在于它的命名方式。
func showPictureSourceOptions() {
var mediaManager = MultiMediaManager(presentingViewController: self)
mediaManager!.showPictureSourceOptions()
}每次调用函数时,我都会创建mediaManager的新局部变量。卸下mediaManager前面的var解决了问题。
https://stackoverflow.com/questions/38954719
复制相似问题