gpt4 book ai didi

ios - swift : UIPickerViewController delegates not called after Class-Extraction

转载 作者:行者123 更新时间:2023-11-28 06:36:30 28 4
gpt4 key购买 nike

我正在开发一个应用程序,该应用程序要求用户对来自不同 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
}

显示从图库中选择图片的 View 。但是当我选择图像时,viewcontroller 只是默默地关闭并且它的委托(delegate)没有被调用。

    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 的新局部变量。删除 mediaManager 前面的 var 解决了这个问题。

关于ios - swift : UIPickerViewController delegates not called after Class-Extraction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38954719/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com