Skip to content

Instantly share code, notes, and snippets.

@mokagio
Created July 26, 2017 02:43
Show Gist options
  • Save mokagio/c167af2bfe3f47dca121dced57c89c7e to your computer and use it in GitHub Desktop.
Save mokagio/c167af2bfe3f47dca121dced57c89c7e to your computer and use it in GitHub Desktop.
TitleAndValueRowWithPresenter.swift
import Eureka
/// This row is build based on the implementation of `ButtonRowWithPresent`, and
/// allows consurmers to set a detail value for the row, which is not possible
/// in the other.
///
/// To set the value use `$0.cellUpdate { cell, _ in cell.detailLabel?.text = "value" }`.
///
/// - See: https://github.com/xmartlabs/Eureka/blob/master/Source/Rows/ButtonRowWithPresent.swift
open class _TitleAndValueRowWithPresenter<VCType: TypedRowControllerType>: Row<LabelCellOf<VCType.RowValue>>, PresenterRowType where VCType: UIViewController {
open var presentationMode: PresentationMode<VCType>?
open var onPresentCallback : ((FormViewController, VCType)->())?
required public init(tag: String?) {
super.init(tag: tag)
displayValueFor = nil
cellStyle = .value1
}
open override func customUpdateCell() {
super.customUpdateCell()
cell.accessoryType = isDisabled ? .none : .disclosureIndicator
}
open override func customDidSelect() {
super.customDidSelect()
if let presentationMode = presentationMode, !isDisabled {
if let controller = presentationMode.makeController(){
controller.row = self
onPresentCallback?(cell.formViewController()!, controller)
presentationMode.present(controller, row: self, presentingController: cell.formViewController()!)
}
else{
presentationMode.present(nil, row: self, presentingController: cell.formViewController()!)
}
}
}
open override func prepare(for segue: UIStoryboardSegue) {
super.prepare(for: segue)
guard let rowVC = segue.destination as? VCType else {
return
}
if let callback = presentationMode?.onDismissCallback{
rowVC.onDismissCallback = callback
}
rowVC.row = self
onPresentCallback?(cell.formViewController()!, rowVC)
}
}
/// A generic row with a button that presents a view controller when tapped
public final class TitleAndValueRowWithWithPresenter<VCType: TypedRowControllerType> : _TitleAndValueRowWithPresenter<VCType>, RowType where VCType: UIViewController {
public required init(tag: String?) {
super.init(tag: tag)
}
}
@mokagio
Copy link
Author

mokagio commented Jul 26, 2017

Just dumping it here because I know that I'll forget about having written this in an app from which I'm now stripping Eureka, but it might come handy in the future.

Of course I'll have to remember having made this gist...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment