Sha256: 8de1b32b458b8b12a64474281d540599743df880ac634d503f44cf99ba9b3ad0

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

motion_require 'base'

module Formotion
  module RowType
    class CheckRow < Base
      include BW::KVO

      def update_cell_value(cell)
        cell.accessoryType = cell.editingAccessoryType = row.value ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone
      end

      # This is actually called whenever again cell is checked/unchecked
      # in the UITableViewDelegate callbacks. So (for now) don't
      # instantiate long-lived objects in them.
      # Maybe that logic should be moved elsewhere?
      def build_cell(cell)
        cell.selectionStyle = self.row.selection_style || UITableViewCellSelectionStyleBlue
        update_cell_value(cell)
        observe(self.row, "value") do |old_value, new_value|
          update_cell_value(cell)
        end
        nil
      end

      def on_select(tableView, tableViewDelegate)
        if !row.editable?
          return
        end
        if row.section.select_one and !row.value
          row.section.rows.each do |other_row|
            other_row.value = (other_row == row)
          end
        elsif !row.section.select_one
          row.value = !row.value
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formotion-1.5.1 lib/formotion/row_type/check_row.rb
formotion-1.5.0 lib/formotion/row_type/check_row.rb
formotion-1.4.0 lib/formotion/row_type/check_row.rb