如何从Eureka的ImageRow访问所选图像?

时间:2016-07-07 00:30:53

标签: ios swift swift2 eureka-forms

如何访问Eureka中ImageRow选择的图像?

form = Section()
            <<< ImageRow("Pic"){
                $0.title = "Picture"
            }.cellSetup { cell, row in

                if let picPath = NSURL(string: _user.pic!),
                    data = NSData(contentsOfURL: picPath) {
                    cell.imageView?.image = UIImage(data: data)
                }
            }

对于文本字段,我这样做是为了获取表单值:

let values = form.values()
if values["Name"]! != nil {
   name = values["Name"] as! String
}

试图找出如何获取图像行的值。我需要将所选图像上传到我的服务器。

3 个答案:

答案 0 :(得分:3)

想出来:

let picture = values["Pic"] as? UIImage

答案 1 :(得分:0)

对于那些试图在没有图像时显示占位符并在选择图像时删除占位符的人,这就是我的方法

<<< ImageRow(FormItems.imageEntryOne) { row in
row.title = "Image #1"
row.noValueDisplayText = "Select"
row.sourceTypes = [.PhotoLibrary, .SavedPhotosAlbum]
row.clearAction = .yes(style: .destructive)
}
.cellUpdate({ (cell, row) in
    cell.accessoryView?.layer.cornerRadius = 4
    cell.accessoryView?.frame = CGRect(x: 0, y: 0, width: 34, height: 34)
}).onChange({ (row) in
    row.noValueDisplayText = row.value == nil ? "Select" : ""
})

答案 2 :(得分:0)

只需遵循此步骤,快速4.x

let imageRow = self.form.rowBy(tag: "ImageRow") as? ImageRow

现在您可以访问imageRow.value了吗?返回UIImage, 这样您就可以使用

guard let imageValue = imageRow?.value else{return}

如果要将其上传到服务器,只需将映像转换为NSdata

let selectedImage = NSData()
selectedImage = imageRow?.value?.jpegData(compressionQuality: 0.3)