Closed Oliver530 closed 6 years ago
How are you acquiring the viewRowImage
value? Are you sure its non-nil? When I tested it here, all I need to do is assign a new image to the viewRowImage?.cell.view?.image
. I've updated my example application to illustrate this - pull a fresh copy to see this in ImageViewViewController.swift
.
Here's the example code I'm using:
+++ Section("Image View with changable image")
<<< SegmentedRow<String> { (row) in
row.title = "Image"
row.options = ["trees", "flower"]
row.value = "trees"
}
.cellSetup { (cell, row) in
cell.segmentedControl.setContentHuggingPriority(UILayoutPriority(rawValue: 750), for: .horizontal)
cell.segmentedControl.apportionsSegmentWidthsByContent = true
}
.onChange { [unowned self] (row) in
guard let imageName = row.value else { return }
guard let imageRow = self.form.rowBy(tag: "xxxx") as? ViewRow<UIImageView> else { return }
let image = UIImage(named: imageName)
imageRow.cell.view!.image = image
}
<<< ViewRow<UIImageView>("xxxx")
.cellSetup { (cell, row) in
// Construct the view for the cell
cell.view = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 300))
cell.view!.contentMode = .scaleAspectFill
cell.view!.clipsToBounds = true
// Get something to display
let image = UIImage(named: "trees")
cell.view!.image = image
// Make the image view occupy the entire row:
cell.viewRightMargin = 0.0
cell.viewLeftMargin = 0.0
cell.viewTopMargin = 0.0
cell.viewBottomMargin = 0.0
}
Here's hat this looks like when running:
Thanks a lot for your super-fast help! I found the mistake on my side:
I set the cell's tag in the cellSetup()-function via row.tag = "myID"
instead of passing it to the constructor. This meant that I could not reference the row.
Thanks for updating the example!
First of all, many thanks for the functionality. That's exactly what I was looking for.
How can I change the content of the series dynamically?
viewRowImage?.cell.view?.image = image
has no effect on the viewDidAppear-Trigger. Updating the row withupdateCell()
orreload()
does not help either.I would be very happy about your help.