Sha256: 040e962706cb703216124cdc3158eecf53f97c2e894395a0f00038d98ec5619d

Contents?: true

Size: 928 Bytes

Versions: 6

Compression:

Stored size: 928 Bytes

Contents

motion_require 'base'

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

      def build_cell(cell)
        cell.selectionStyle = self.row.selection_style || UITableViewCellSelectionStyleNone
        switchView = UISwitch.alloc.initWithFrame(CGRectZero)
        switchView.accessibilityLabel = (row.title || "") + " Switch"
        cell.accessoryView = cell.editingAccessoryView = switchView
        switchView.setOn(row.value || false, animated:false)
        switchView.when(UIControlEventValueChanged) do
          break_with_semaphore do
            row.value = switchView.isOn
          end
        end
        switchView.userInteractionEnabled = row.editable?
        observe(self.row, "value") do |old_value, new_value|
          break_with_semaphore do
            switchView.setOn(row.value || false, animated: false)
          end
        end
        nil
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
formotion-1.8 lib/formotion/row_type/switch_row.rb
formotion-1.7 lib/formotion/row_type/switch_row.rb
formotion-1.6 lib/formotion/row_type/switch_row.rb
formotion-1.5.1 lib/formotion/row_type/switch_row.rb
formotion-1.5.0 lib/formotion/row_type/switch_row.rb
formotion-1.4.0 lib/formotion/row_type/switch_row.rb