RSDTableStepViewController

open class RSDTableStepViewController : RSDStepViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UITextViewDelegate, RSDTableDataSourceDelegate, RSDPickerObserver, RSDButtonCellDelegate, RSDTaskViewControllerDelegate

RSDTableStepViewController is a custom instance of RSDStepViewController. Its subviews include a UITableView, a RSDNavigationFooterView, which may or may not be embedded in the tableView as its footerView, and a RSDNavigationHeaderView, which is embedded in the tableView as its headerView.

This class populates the contents and properties of the headerView and navigationView based on the associated RSDStep, which is expected to be set before presenting the view controller.

An instance of RSDFormStepDataSource is created by setupModel() and assigned to property tableData. This method is called by viewWillAppear() and serves as the UITableViewDataSource. The tableData also keeps track of answers that are derived from the user’s input and it provides the RSDResult that is appended to the RSDTaskViewModel associated with this task.

This class is responsible for acquiring input from the user, validating it, and supplying it as an answer to to the model (tableData). This is typically done in delegate callbacks from various input views, such as UITableView (didSelectRow) or UITextField (valueDidChange or shouldChangeCharactersInRange).

Some RSDSteps, such as RSDFactory.StepType.instruction, require no user input (and have no input fields). These steps will result in a tableData that has no sections and, therefore, no rows. So the tableView will simply have a headerView, no rows, and a footerView.

  • The table view associated with this view controller. This will be created during viewDidLoad() with a default set up if it is nil. If this view controller is loaded from a nib or storyboard, then it should set this outlet using the interface builder.

    Declaration

    Swift

    @IBOutlet
    open var tableView: UITableView!
  • The data source for this table.

    Declaration

    Swift

    open var tableData: RSDTableDataSource? { get }
  • Convenience property for accessing the form step (if casting the step to a RSDFormUIStep is applicable).

    Declaration

    Swift

    public var formStep: RSDFormUIStep? { get }
  • Static method to determine if this view controller class supports the provided step.

    Declaration

    Swift

    open class func doesSupport(_ step: RSDStep) -> Bool
  • Should the view controller tableview include a header? If true, then by default, a RSDStepHeaderView will be added in viewDidLoad() if the view controller was not loaded using a storyboard or nib that included setting the navigationFooter property.

    Declaration

    Swift

    open var shouldShowHeader: Bool
  • Should the view controller tableview include a footer? If true, then by default, a RSDNavigationFooterView will be added in viewDidLoad() if the view controller was not loaded using a storyboard or nib that included setting the navigationFooter property.

    Declaration

    Swift

    open var shouldShowFooter: Bool
  • The background color tile for the table

    Declaration

    Swift

    open var tableBackgroundColorTile: RSDColorTile!
  • Override viewDidLoad() to add the table view, navigation header, and navigation footer if needed.

    Declaration

    Swift

    override open func viewDidLoad()
  • Override viewWillAppear() to set up the tableData data source model and add a keyboard listener.

    Declaration

    Swift

    override open func viewWillAppear(_ animated: Bool)
  • Override viewWillDisappear() to remove listeners and dismiss the keyboard.

    Declaration

    Swift

    override open func viewWillDisappear(_ animated: Bool)
  • Override viewDidLayoutSubviews() to set up the navigation footer either as the table footer or as a sticky footer.

    Declaration

    Swift

    override open func viewDidLayoutSubviews()
  • Override to set the background color of the table.

    Declaration

    Swift

    override open func setColorStyle(for placement: RSDColorPlacement, background: RSDColorTile)
  • The UI hints that are supported by this view controller.

    Declaration

    Swift

    open class var supportedUIHints: Set<RSDFormUIHint> { get }
  • Override and set to an appropriate RSDTableDataSource instance.

    Declaration

    Swift

    override open func instantiateStepViewModel(for step: RSDStep, with parent: RSDPathComponent?) -> RSDStepViewPathComponent
  • Creates and assigns a new instance of the model. The default implementation will instantiate RSDFormStepDataSourceObject and set this as the tableData.

    Declaration

    Swift

    open func setupModel()
  • Register the given reuse identifier. This is a factory method that is called before dequeuing a table cell. Overrides of this method should first check to see if the reuse identifier has already been registered and if not, do so by calling tableView.register(, forCellReuseIdentifier:) with either a nib or a class.

    Declaration

    Swift

    open func registerReuseIdentifierIfNeeded(_ reuseIdentifier: String)
  • Register the given reuse identifier for a section header or footer. This is a factory method that is called before dequeuing a table section view. Overrides of this method should first check to see if the reuse identifier has already been registered and if not, do so by calling tableView.register(, forHeaderFooterViewReuseIdentifier:) with either a nib or a class.

    Declaration

    Swift

    open func registerSectionReuseIdentifierIfNeeded(_ reuseIdentifier: String)
  • Declaration

    Swift

    override open func defaultBackgroundColorTile(for placement: RSDColorPlacement) -> RSDColorTile
  • Override the set up of the header to set the background color for the table view and adjust the minimum height.

    Declaration

    Swift

    open override func setupHeader(_ header: RSDStepNavigationView)
  • Auto layout constraint constants for the margin used at the bottom of the main view and the default tableView row height.

    Declaration

    Swift

    open var constants: RSDTableStepLayoutConstants { get }

    Return Value

    A struct with the layout constants

  • Declaration

    Swift

    override open func goForward()
  • Declaration

    Swift

    override open func stop()
  • Return the number of sections. The default implementation returns the section count of the tableData data source.

    Declaration

    Swift

    open func numberOfSections(in tableView: UITableView) -> Int

    Parameters

    tableView

    The table view.

    Return Value

    The number of sections.

  • Return the number of rows in a given section. The default implementation returns the row count of the tableData data source.

    Declaration

    Swift

    open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int

    Parameters

    tableView

    The table view.

    section

    The section for the table view.

    Return Value

    The number of rows in the given section.

  • Instantiate or dequeue a cell for the given index path. The default implementation will call dequeueCell(in:, at:) to dequeue the cell followed by calling configure(cell:, in:, at:) to configure the cell.

    Declaration

    Swift

    open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

    Parameters

    tableView

    The table view.

    indexPath

    The given index path.

    Return Value

    The table view cell configured for this index path.

  • Dequeues a section header if the title for the section is non-nil.

    Declaration

    Swift

    open func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
  • Dequeue a cell that is appropriate for the item at the given index path. By default, this method will call reuseIdentifier(for:) followed by registerReuseIdentifierIfNeeded() to register the table view cell reuse identifier before calling dequeueReusableCell() on the given table view.

    Declaration

    Swift

    open func dequeueCell(in tableView: UITableView, for indexPath: IndexPath) -> UITableViewCell

    Parameters

    tableView

    The table view.

    indexPath

    The given index path.

    Return Value

    The table view cell dequeued for this index path.

  • Returns the cell reuse identifier for a given index path.

    By default, this will look for a RSDTableItem at the given index path and return the reuseIdentifier property on that object. If there isn’t a table item in the tableData associated with this index path then this is a failure. The default behavior is to throw an assertion and return a placeholder cell identifier.

    Declaration

    Swift

    open func reuseIdentifier(for indexPath: IndexPath) -> String

    Parameters

    indexPath

    The given index path.

    Return Value

    The reuse identifier for the given index path.

  • Configure a cell that is appropriate for the item at the given index path.

    Declaration

    Swift

    open func configure(cell: UITableViewCell, in tableView: UITableView, at indexPath: IndexPath)

    Parameters

    cell

    The cell to configure.

    tableView

    The table view.

    indexPath

    The given index path.

  • For a given text input, refresh the answer from the table item to the cell. Typically, when saving an answer for a user input, the value that was entered by the user should be kept. However, if the controller modifies the answer for some reason, that updated value should be honored.

    Declaration

    Swift

    open func refreshAnswer(at indexPath: IndexPath)
  • Instantiate a keyboard accessory view based on the current ‘navigationFooter’.

    Declaration

    Swift

    open func instantiateKeyboardAccessoryView() -> UIView?
  • Instantiate the appropriate picker view for the given input item.

    Declaration

    Swift

    open func instantiatePickerView(textInputItem: RSDTextInputTableItem, indexPath: IndexPath) -> (RSDPickerViewProtocol & UIView)?

    Parameters

    textInputItem

    The table item.

    indexPath

    The index path.

  • Handle the selection of a row.

    The base class implementation can handle the following ui hints:

    1. List - Selects the given index path as the current selection. This will also deselect other rows if the form data type is single choice.
    2. Textfield - Calls becomeFirstResponder() to present the keyboard.

    Declaration

    Swift

    open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
  • Get the next responder (table cell or text field) for the next table item after the given index path.

    Declaration

    Swift

    open func nextResponder(after indexPath: IndexPath) -> UIResponder?

    Parameters

    indexPath

    The index path of the next field.

    Return Value

    The next responder or nil if this is the last item.

  • Called when a user action on a cell or button is linked to a choice item.

    Declaration

    Swift

    open func didSelectItem(_ item: RSDTableItem, at indexPath: IndexPath)
  • Called when a user action on a cell or button is linked to a modal item.

    Declaration

    Swift

    open func didSelectModalItem(_ modalItem: RSDModalStepTableItem, at indexPath: IndexPath)
  • When a text field gets focus, assign it as the active text field (to allow resigning active if the user taps the forward button) and scroll it into view above the keyboard.

    Declaration

    Swift

    open func textFieldDidBeginEditing(_ textField: UITextField)
  • Resign first responder on Enter key tapped.

    Declaration

    Swift

    open func textFieldShouldReturn(_ textField: UITextField) -> Bool
  • Enable the next button as soon as the text field entry has changed.

    Declaration

    Swift

    open func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool
  • Validate and save the text field result.

    Declaration

    Swift

    open func textFieldDidEndEditing(_ textField: UITextField)
  • Get the table item associated with a given text field.

    Declaration

    Swift

    public func tableItem(for textInputView: RSDStepTextInputView) -> RSDTextInputTableItem?
  • Validate the text field value and save the answer if valid.

    Declaration

    Swift

    @discardableResult
    public func validateAndSave(textInputView: RSDStepTextInputView? = nil) -> Bool
  • Save answer back to the data source.

    Declaration

    Swift

    @discardableResult
    open func saveAnswer(newValue: Any, at indexPath: IndexPath) -> Bool
  • Show a validation error message that is appropriate for the given context.

    Declaration

    Swift

    open func showValidationError(title: String?, message: String?, context: RSDInputFieldError.Context?, at indexPath: IndexPath)
  • MARK: RSDButtonCellDelegate

    Declaration

    Swift

    open func didTapButton(on cell: RSDButtonCell)
  • Called when the answers tracked by the data source change.

    Declaration

    Swift

    open func answersDidChange(in section: Int)

    Parameters

    section

    The section that changed.

  • Called when the answers tracked by the data source change.

    Declaration

    Swift

    open func tableDataSource(_ dataSource: RSDTableDataSource, didChangeAnswersIn section: Int)

    Parameters

    dataSource

    The calling data source.

    section

    The section that changed.

  • Called before editing the table rows and sections.

    Declaration

    Swift

    open func tableDataSourceWillBeginUpdate(_ dataSource: RSDTableDataSource)
  • Called to remove rows from a data source. Calls to this method should be wrapped within a begin/end update.

    Declaration

    Swift

    open func tableDataSource(_ dataSource: RSDTableDataSource, didRemoveRows removedRows: [IndexPath], with animation: RSDUIRowAnimation)
  • Called to add rows to a data source. Calls to this method should be wrapped within a begin/end update.

    Declaration

    Swift

    open func tableDataSource(_ dataSource: RSDTableDataSource, didAddRows addedRows: [IndexPath], with animation: RSDUIRowAnimation)
  • Called after editing the table rows and sections.

    Declaration

    Swift

    open func tableDataSourceDidEndUpdate(_ dataSource: RSDTableDataSource)