我可以这样调用imagePicker,程序正在等待图像选择

时间:2016-10-01 23:36:23

标签: swift3

我的委托总是在自定义表格单元格中为我的图像返回nil。 PhotoTakingHelper只是用于imagepicker设置的类。 如何暂停程序选择图像?

CustomCell类中的方法:

window.confirm

tableView类中的方法:

@IBAction func loadImageButtonTapped(_ sender: UIButton) {
            loadingImage=true
            if delegate != nil {
               let (image,name) = delegate.loadImageForQuestionAction(question: question)
                 print("Delegate return \(image)")
                imageInCreatingCell = image
                nameInCreatingCell = name

                //loadImageButton.isHidden = true

            }
        }

PhotoTakingHelper中的方法:

func loadImageForQuestionAction(question: Question) -> (UIImage?,String?) {

        var returnImage:UIImage?
        var returnName:String?

            self.photoTakingHelper=PhotoTakingHelper(viewcontroller: self, callback: { (image:UIImage?,name:String?) in
                if let photoImage = image {
                    print(photoImage)
                    print(name)
                    returnImage=photoImage
                    returnName=name

                    //NEED SHOWING IMAGE NAME HOW LABEL
                    print("loadImageAction")
                }
            })
        return (returnImage,returnName)
    }

1 个答案:

答案 0 :(得分:0)

更新:

func loadImageForQuestionAction(question: Question, completion: @escaping (UIImage?, String?) -> ()) {
        var returnImage:UIImage?
        var returnName:String?

        self.photoTakingHelper=PhotoTakingHelper(viewcontroller: self, callback: { (image:UIImage?,name:String?) in
            DispatchQueue.main.async {
                if let photoImage = image {
                    print(photoImage)
                    print(name)
                    returnImage=photoImage
                    returnName=name

                    completion(returnImage,returnName)
                    //NEED SHOWING IMAGE NAME HOW LABEL
                    print("loadImageAction")
                } else {
                    completion(returnImage,returnName)
                }
            }
        })
    }