class Formotion::Row
Constants
- BOOLEAN_PROPERTIES
- PROPERTIES
- SERIALIZE_PROPERTIES
Attributes
Index of the row in the section
RowType
object
callback for what happens when the user starts editing text_field
.
callback for when a row is tapped
callback for when a row is exited
callback for what happens when the user hits the enter key while editing text_field
callback for what happens when the user taps a ButtonRow
The reuse-identifier used in UITableViews By default is a stringification of section.index and row.index, thus is unique per row (bad for memory, to fix later.)
Reference to the row's section
Owning template row, if applicable
reference to the row's UITextField
.
Public Class Methods
Formotion::Base::new
# File lib/formotion/row/row.rb, line 165 def initialize(params = {}) super BOOLEAN_PROPERTIES.each { |prop| Formotion::Conditions.assert_nil_or_boolean(self.send(prop)) } @template_children = [] end
Public Instance Methods
called after section and index have been assigned
# File lib/formotion/row/row.rb, line 175 def after_create if self.type == :template self.object.update_template_rows end end
# File lib/formotion/row/row.rb, line 273 def auto_capitalization=(value) @auto_capitalization = const_int_get("UITextAutocapitalizationType", value) end
# File lib/formotion/row/row.rb, line 269 def auto_correction=(value) @auto_correction = const_int_get("UITextAutocorrectionType", value) end
# File lib/formotion/row/row.rb, line 289 def editable=(editable) case editable when TrueClass when FalseClass when NSNull editable = false when NilClass editable = false when NSString editable = (editable == "true") else raise Formotion::InvalidClassError, "Invalid class for `Row#editable`: #{editable.inspect}; should be TrueClass, FalseCLass, or NSString" end @editable = editable end
# File lib/formotion/row/row.rb, line 305 def editable? if !self.editable.nil? return self.editable end true end
# File lib/formotion/row/row.rb, line 196 def form self.section.form end
# File lib/formotion/row/row.rb, line 192 def index_path NSIndexPath.indexPathForRow(self.index, inSection:self.section.index) end
getter overrides
# File lib/formotion/row/row.rb, line 237 def items if @items.respond_to?(:call) @items = @items.call end @items end
Methods for making cells Called in UITableViewDataSource methods in form_delegate.rb
# File lib/formotion/row/row.rb, line 352 def make_cell if self.object.nil? raise Formotion::NoRowTypeError, "No row type specified for row #{self.index_path.row} in section #{self.index_path.section}; specify a :type" end cell, text_field = Formotion::RowCellBuilder.make_cell(self) @text_field = text_field self.object.after_build(cell) cell end
# File lib/formotion/row/row.rb, line 204 def next_row # if there are more rows in this section, use that. return self.section.rows[self.index + 1] if self.index < (self.section.rows.count - 1) # if there are more sections, then use the first row of that section. return self.section.next_section.rows[0] if self.section.next_section nil end
# File lib/formotion/row/row.rb, line 319 def on_begin(&block) self.on_begin_callback = block end
# File lib/formotion/row/row.rb, line 338 def on_delete(&block) self.on_delete_callback = block # set on_tap for all template children if self.type == :template for templ in self.template_children do templ.on_delete_callback = block end end end
# File lib/formotion/row/row.rb, line 323 def on_end(&block) self.on_end_callback = block end
setters for callbacks
# File lib/formotion/row/row.rb, line 315 def on_enter(&block) self.on_enter_callback = block end
Used in :button type rows
# File lib/formotion/row/row.rb, line 328 def on_tap(&block) self.on_tap_callback = block # set on_tap for all template children if self.type == :template for templ in self.template_children do templ.on_tap_callback = block end end end
# File lib/formotion/row/row.rb, line 214 def previous_row return self.section.rows[self.index - 1] if self.index > 0 # if there are more sections, then use the first row of that section. return self.section.previous_section.rows[-1] if self.section.previous_section nil end
# File lib/formotion/row/row.rb, line 251 def range=(range) if range case range when Range # all good when Array range = Range.new(range[0], range[1]) else raise Formotion::InvalidClassError, "Attempted Row.range = #{range.inspect} should be of type Range or Array" end end @range = range end
# File lib/formotion/row/row.rb, line 265 def return_key=(value) @return_key = const_int_get("UIReturnKey", value) end
# File lib/formotion/row/row.rb, line 285 def selection_style=(style) @selection_style = const_int_get("UITableViewCellSelectionStyle", style || :blue) end
# File lib/formotion/row/row.rb, line 382 def subform=(subform) @subform = subform # enables you do to row.subform.to_form @subform.instance_eval do def to_form return @hash_subform if @hash_subform if self.is_a? Hash @hash_subform = Formotion::Form.new(self) elsif not self.is_a? Formotion::Form raise Formotion::InvalidClassError, "Attempted subform = '#{self.inspect}' should be of type Formotion::Form or Hash" end @hash_subform ||= self end end @subform end
# File lib/formotion/row/row.rb, line 227 def subform? self.type.to_s == "subform" end
# File lib/formotion/row/row.rb, line 231 def templated? !!self.template_parent end
# File lib/formotion/row/row.rb, line 281 def text_alignment=(alignment) @text_alignment = const_int_get("NSTextAlignment", alignment) end
# File lib/formotion/row/row.rb, line 386 def to_form return @hash_subform if @hash_subform if self.is_a? Hash @hash_subform = Formotion::Form.new(self) elsif not self.is_a? Formotion::Form raise Formotion::InvalidClassError, "Attempted subform = '#{self.inspect}' should be of type Formotion::Form or Hash" end @hash_subform ||= self end
Retreiving data
Formotion::Base#to_hash
# File lib/formotion/row/row.rb, line 371 def to_hash h = super if h[:range] && h[:range].is_a?(Range) h[:range] = [self.range.begin, self.range.end] end if subform? h[:subform] = self.subform.to_form.to_hash end h end
setter overrides
# File lib/formotion/row/row.rb, line 246 def type=(type) @object = Formotion::RowType.for(type).new(self) @type = type end
Called on every tableView:cellForRowAtIndexPath: so keep implementation details minimal
# File lib/formotion/row/row.rb, line 364 def update_cell(cell) self.object.update_cell(cell) cell end
pseudo-properties
# File lib/formotion/row/row.rb, line 184 def value_for_save_hash if self.object.respond_to? :value_for_save_hash self.object.value_for_save_hash else self.value end end
Private Instance Methods
# File lib/formotion/row/row.rb, line 400 def const_int_get(base, value) return value if value.is_a? Integer value = value.to_s.camelize Kernel.const_get("#{base}#{value}") end
Looks like RubyMotion adds UIKit constants at compile time. If you don't use these directly in your code, they don't get added to Kernel and const_int_get
crashes.
# File lib/formotion/row/row.rb, line 410 def load_constants_hack [UITextAutocapitalizationTypeNone, UITextAutocapitalizationTypeWords, UITextAutocapitalizationTypeSentences,UITextAutocapitalizationTypeAllCharacters, UITextAutocorrectionTypeNo, UITextAutocorrectionTypeYes, UITextAutocorrectionTypeDefault, UIReturnKeyDefault, UIReturnKeyGo, UIReturnKeyGoogle, UIReturnKeyJoin, UIReturnKeyNext, UIReturnKeyRoute, UIReturnKeySearch, UIReturnKeySend, UIReturnKeyYahoo, UIReturnKeyDone, UIReturnKeyEmergencyCall, UITextFieldViewModeNever, UITextFieldViewModeAlways, UITextFieldViewModeWhileEditing, UITextFieldViewModeUnlessEditing, NSDateFormatterShortStyle, NSDateFormatterMediumStyle, NSDateFormatterLongStyle, NSDateFormatterFullStyle, NSTextAlignmentRight, NSTextAlignmentCenter, NSTextAlignmentLeft ] end