Sha256: c55981b1df2b0061478ede11ab9c2d7603fc2d0ba54273b2ebe6c1b11f87914b

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module Formotion
  module RowType
    class OptionsRow < Base
      include BW::KVO
      include RowType::ItemsMapper

      def build_cell(cell)
        cell.selectionStyle = UITableViewCellSelectionStyleNone

        segmentedControl = UISegmentedControl.alloc.initWithItems(item_names || [])
        segmentedControl.selectedSegmentIndex = name_index_of_value(row.value) if row.value
        segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar
        cell.accessoryView = cell.editingAccessoryView = segmentedControl

        segmentedControl.when(UIControlEventValueChanged) do
          break_with_semaphore do
            row.value = value_for_name_index(segmentedControl.selectedSegmentIndex)
          end
        end
        observe(self.row, "value") do |old_value, new_value|
          break_with_semaphore do
            if row.value
              segmentedControl.selectedSegmentIndex = name_index_of_value(row.value)
            else
              segmentedControl.selectedSegmentIndex = UISegmentedControlNoSegment
            end
          end
        end

        nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formotion-1.1.5 lib/formotion/row_type/options_row.rb