I have a PushRow, how can i style the tableView/cells of the pushed SelectorViewController? With cellSetup only the PushRow itself can be styled but not the tableView and cells of the pushed VC. Currently i use a custom SelectorViewController subclass which will be creates by the .Show presentationMode, or its controllerProvider respectively.
Sample:
<<< PushRow<String>() {
$0.presentationMode = .Show(controllerProvider: .Callback(builder: { () -> CustomSelectorViewController < String> in
return CustomSelectorViewController<String>()
}), completionCallback: nil)
}
@dhf I added the ability to customize the selector row.
You can do it by setting up selectableRowCellUpdate property from onPresent callback as shown below...
<<< PushRow<Emoji>() {
$0.options = [馃拋, 馃崘, 馃懄, 馃悧, 馃惣, 馃惢]
$0.value = 馃懄
}.onPresent({ (_, presentingVC) -> () in
presentingVC.selectableRowCellUpdate = { cell, row in
cell.contentView.backgroundColor = .orangeColor()
}
})
Regards
@mtnbarreto Is there any way to apply this to a MultipleSelectorRow<String>? I'm hoping to add a detail line to the cells below the existing value line.
Thanks!
@robbiet480 done!
@mtnbarreto Thanks so much!
@mtnbarreto Could $0.cellStyle (referenced in #257) also exist for MultipleSelectorRow (and I would assume by implementing it for that it would also work for SelectorViewController)? I thought that this fix would allow me to set the cellStyle from within selectableRowCellUpdate but it appears that I can't.
I'm hoping to have MultipleSelectorRow be UITableViewCellStyle.Subtitle so that the detailTextLabel appears below the main value...
@robbiet480 Easiest way to change the cellType of Multiple Selector presented view controller rows is...
ListCheckRow<String>.defaultRowInitializer = { row in
row.cellStyle = UITableViewCellStyle.Subtitle
}
this will change cellType value of every
ListCheckRow<String>cell no matters from where it was created.
then use selectableRowCellUpdate to set up cell detailTextLabel property.
A more complex and flexible solution could be creating your own MultipleSelectorRow (custom row), lets call it MyMultipleSelectorRow.
usage of the new row....
<<< MyMultipleSelectorRow<Emoji>(){
$0.title = "MultipleSelectorRow"
$0.options = [馃拋馃徎, 馃崘, 馃懄馃徏, 馃悧, 馃惣, 馃惢]
$0.value = [馃懄馃徏, 馃崘, 馃悧]
}
.onPresent { from, to in
..
to.selectableRowCellUpdate = { cell, row in
cell.detailTextLabel?.text = "Hi"
}
}
pretty similar to build-in Eureka row ;).
Now let's implement the custom row....
Since we only want to make a little tweak we can extend from GenericMultipleSelectorRow generic type which is the MultipleSelectorRow base class.
These are the generic types that must be specified when creating a
GenericMultipleSelectorRow<T: Hashable, Cell: CellType, VCType: TypedRowControllerType....>
VCTypeis the view controllers that will be presented to select the values.
public final class MyMultipleSelectorRow<T: Hashable> : GenericMultipleSelectorRow<T, PushSelectorCell<Set<T>>, MyMultipleSelectorViewController<T>>, RowType {
public required init(tag: String?) {
super.init(tag: tag)
}
}
As you may have already noticed we are using MyMultipleSelectorViewController as VCType.
MyMultipleSelectorViewController will be responsible for changing cellStyle of each selector controller's row...
Once again we will extend from default MultipleSelectorRow selector view controller, just to make this small tweak.
public class MyMultipleSelectorViewController<T:Hashable> : MultipleSelectorViewController<T> {
public override func viewDidLoad() {
super.viewDidLoad()
form.first!.forEach { $0.cellStyle = .Subtitle } // tweak
}
}
behind the scenes Eureka uses
presentationModeproperty to create and present the selector view controller as the code snippet below shows
presentationMode = .Show(controllerProvider: ControllerProvider.Callback { return VCType() }, completionCallback: { vc in vc.navigationController?.popViewControllerAnimated(true) })
For further info take a look at GenericMultipleSelectorRow implementation.
Hope this clarify something and helps you!
@mtnbarreto I don't think i've ever received such a super helpful reply from anyone on Github before haha. Thank you so much, it should've been obvious to use defaultRowInitializer but I was trying to do it with MultipleSelectorRow instead!
Hey @mtnbarreto, how would I go about customizing the background color of the SelectorViewController's view without subclassing it? Thanks!
Most helpful comment
@mtnbarreto I don't think i've ever received such a super helpful reply from anyone on Github before haha. Thank you so much, it should've been obvious to use
defaultRowInitializerbut I was trying to do it withMultipleSelectorRowinstead!