1

如何访问 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
}

试图弄清楚如何获得图像行的值。我需要将所选图像上传到我的服务器。

4

3 回答 3

3

弄清楚了:

let picture = values["Pic"] as? UIImage
于 2016-07-07T01:01:45.883 回答
0

Simply follow this , swift 4.x

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

now you can access imageRow.value? which returns UIImage, so you can use this

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

if you want to upload it to server , simply convert the image to NSdata

let selectedImage = NSData()
selectedImage = imageRow?.value?.jpegData(compressionQuality: 0.3)
于 2018-12-27T07:27:23.860 回答
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" : ""
})
于 2018-08-04T05:29:25.800 回答