class Formotion::Row

Constants

BOOLEAN_PROPERTIES
PROPERTIES
SERIALIZE_PROPERTIES

Attributes

index[RW]

Index of the row in the section

object[RW]

RowType object

on_begin_callback[RW]

callback for what happens when the user starts editing text_field.

on_delete_callback[RW]

callback for when a row is tapped

on_end_callback[RW]

callback for when a row is exited

on_enter_callback[RW]

callback for what happens when the user hits the enter key while editing text_field

on_tap_callback[RW]

callback for what happens when the user taps a ButtonRow

reuse_identifier[RW]

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.)

section[RW]

Reference to the row's section

template_children[RW]
template_parent[RW]

Owning template row, if applicable

text_field[R]

reference to the row's UITextField.

Public Class Methods

new(params = {}) click to toggle source
Calls superclass method 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

after_create() click to toggle source

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
auto_capitalization=(value) click to toggle source
# File lib/formotion/row/row.rb, line 273
def auto_capitalization=(value)
  @auto_capitalization = const_int_get("UITextAutocapitalizationType", value)
end
auto_correction=(value) click to toggle source
# File lib/formotion/row/row.rb, line 269
def auto_correction=(value)
  @auto_correction = const_int_get("UITextAutocorrectionType", value)
end
button?() click to toggle source
# File lib/formotion/row/row.rb, line 223
def button?
  object.button?
end
clear_button=(value) click to toggle source
# File lib/formotion/row/row.rb, line 277
def clear_button=(value)
  @clear_button = const_int_get("UITextFieldViewMode", value)
end
editable=(editable) click to toggle source
# 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
editable?() click to toggle source
# File lib/formotion/row/row.rb, line 305
def editable?
  if !self.editable.nil?
    return self.editable
  end
  true
end
form() click to toggle source
# File lib/formotion/row/row.rb, line 196
def form
  self.section.form
end
index_path() click to toggle source
# File lib/formotion/row/row.rb, line 192
def index_path
  NSIndexPath.indexPathForRow(self.index, inSection:self.section.index)
end
items() click to toggle source

getter overrides

# File lib/formotion/row/row.rb, line 237
def items
  if @items.respond_to?(:call)
    @items = @items.call
  end
  @items
end
make_cell() click to toggle source

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
next_row() click to toggle source
# 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
on_begin(&block) click to toggle source
# File lib/formotion/row/row.rb, line 319
def on_begin(&block)
  self.on_begin_callback = block
end
on_delete(&block) click to toggle source
# 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
on_end(&block) click to toggle source
# File lib/formotion/row/row.rb, line 323
def on_end(&block)
  self.on_end_callback = block
end
on_enter(&block) click to toggle source

setters for callbacks

# File lib/formotion/row/row.rb, line 315
def on_enter(&block)
  self.on_enter_callback = block
end
on_tap(&block) click to toggle source

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
previous_row() click to toggle source
# 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
range=(range) click to toggle source
# 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
return_key=(value) click to toggle source
# File lib/formotion/row/row.rb, line 265
def return_key=(value)
  @return_key = const_int_get("UIReturnKey", value)
end
selection_style=(style) click to toggle source
# File lib/formotion/row/row.rb, line 285
def selection_style=(style)
  @selection_style = const_int_get("UITableViewCellSelectionStyle", style || :blue)
end
subform=(subform) click to toggle source
# 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
subform?() click to toggle source
# File lib/formotion/row/row.rb, line 227
def subform?
  self.type.to_s == "subform"
end
templated?() click to toggle source
# File lib/formotion/row/row.rb, line 231
def templated?
  !!self.template_parent
end
text_alignment=(alignment) click to toggle source
# File lib/formotion/row/row.rb, line 281
def text_alignment=(alignment)
  @text_alignment = const_int_get("NSTextAlignment", alignment)
end
to_form() click to toggle source
# 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
to_hash() click to toggle source

Retreiving data

Calls superclass method 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
type=(type) click to toggle source

setter overrides

# File lib/formotion/row/row.rb, line 246
def type=(type)
  @object = Formotion::RowType.for(type).new(self)
  @type = type
end
update_cell(cell) click to toggle source

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
value_for_save_hash() click to toggle source

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

const_int_get(base, value) click to toggle source
# 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
load_constants_hack() click to toggle source

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