swift:在Class-Extraction之后没有调用的UIPickerViewController委托

我正在开发一个应用程序,要求用户从不同的ViewController中挑选图片。 我想为此目的提取课程。 但是在提取类之后, UIPickerViewControllerdelegate方法没有被调用。

现在,我在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) } 

我整天都在摸不着头脑,但我仍然不知道发生了什么。

这些代码没有错。 问题在于它的调用方式。

 func showPictureSourceOptions() { var mediaManager = MultiMediaManager(presentingViewController: self) mediaManager!.showPictureSourceOptions() } 

每次调用函数时,我都在创建mediaManager新局部变量。 删除varmediaManager前面修复了问题。