首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >swift :类提取后未调用UIPickerViewController委托

swift :类提取后未调用UIPickerViewController委托
EN

Stack Overflow用户
提问于 2016-08-15 20:02:11
回答 1查看 540关注 0票数 1

我在一个应用程序上工作,这需要用户采取自拍图像从不同的ViewController。为了这个目的,我想提取类。但是在提取类之后,UIPickerViewControllerdelegate方法不会被调用。

现在,我在MultiMediaManager.swift文件中有一个名为MultiMediaManager的类。

代码语言:javascript
复制
    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 
    }

将显示用于从图库中挑选图片的视图。但是当我选择图像时,视图控制器只是默默地不高兴,它的委托也不会被调用。

代码语言:javascript
复制
    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    // break point does not stop here. nither print statement work.

      viewController?.dismissViewControllerAnimated(true, completion: nil)
}

我已经挠头一整天了,但我还是不知道发生了什么事。

EN

回答 1

Stack Overflow用户

发布于 2016-08-16 13:06:11

这些代码没有任何问题。问题在于它的命名方式。

代码语言:javascript
复制
func showPictureSourceOptions() {
        var mediaManager = MultiMediaManager(presentingViewController: self)
        mediaManager!.showPictureSourceOptions()
    }

每次调用函数时,我都会创建mediaManager的新局部变量。卸下mediaManager前面的var解决了问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38954719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档