Class: Formotion::RowType::PickerRow

Inherits:
StringRow show all
Includes:
ItemsMapper, MultiChoiceRow
Defined in:
lib/formotion/row_type/picker_row.rb

Constant Summary

Constants inherited from StringRow

StringRow::TEXT_FIELD_TAG

Instance Attribute Summary

Attributes inherited from Base

#row, #tableView

Instance Method Summary collapse

Methods included from MultiChoiceRow

#add_callbacks, #build_cell

Methods included from ItemsMapper

#item_names, #item_names_hash, #items, #name_for_value, #name_index_of_value, #value_for_name, #value_for_name_index

Methods inherited from StringRow

#add_callbacks, #build_cell, #done_editing, #keyboardType, #on_select

Methods inherited from Base

#_on_select, #after_delete, #break_with_semaphore, #build_cell, #button?, #cellEditingStyle, #cell_style, #delete_row, #done_editing, field_buffer, #indentWhileEditing?, #initialize, #input_accessory_view, #on_delete, #on_select, #update_cell, #with_semaphore

Constructor Details

This class inherits a constructor from Formotion::RowType::Base

Instance Method Details

#after_build(cell) ⇒ Object



11
12
13
14
# File 'lib/formotion/row_type/picker_row.rb', line 11

def after_build(cell)
  self.row.text_field.inputView = self.picker
  self.row.text_field.text = name_for_value(row.value).to_s
end

#numberOfComponentsInPickerView(pickerView) ⇒ Object



32
33
34
# File 'lib/formotion/row_type/picker_row.rb', line 32

def numberOfComponentsInPickerView(pickerView)
  1
end

#on_change(text_field) ⇒ Object



48
49
50
51
52
# File 'lib/formotion/row_type/picker_row.rb', line 48

def on_change(text_field)
  break_with_semaphore do
    row.value = value_for_name(text_field.text)
  end
end

#pickerObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/formotion/row_type/picker_row.rb', line 16

def picker
  @picker ||= begin
    picker = UIPickerView.alloc.initWithFrame(CGRectZero)
    picker.showsSelectionIndicator = true
    picker.hidden = false
    picker.dataSource = self
    picker.delegate = self

    picker
  end

  select_picker_value(row.value) if self.row.value

  @picker
end

#pickerView(pickerView, didSelectRow: index, inComponent: component) ⇒ Object



36
37
38
# File 'lib/formotion/row_type/picker_row.rb', line 36

def pickerView(pickerView, numberOfRowsInComponent:component)
  self.items.size
end

#row_valueObject



68
69
70
# File 'lib/formotion/row_type/picker_row.rb', line 68

def row_value
  name_for_value(row.value)
end

#select_picker_value(new_value) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/formotion/row_type/picker_row.rb', line 59

def select_picker_value(new_value)
  picker_row = name_index_of_value(new_value)
  if picker_row != nil
    @picker.selectRow(picker_row, inComponent:0, animated:false)
  else
    warn "Picker item '#{row.value}' not found in #{row.items.inspect} for '#{row.key}'"
  end
end

#update_text_field(new_value) ⇒ Object



54
55
56
57
# File 'lib/formotion/row_type/picker_row.rb', line 54

def update_text_field(new_value)
  self.row.text_field.text = name_for_value(new_value)
  select_picker_value(new_value)
end