Class: Formotion::RowType::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/formotion/row_type/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Base

Returns a new instance of Base.



18
19
20
# File 'lib/formotion/row_type/base.rb', line 18

def initialize(row)
  @row = row
end

Instance Attribute Details

#rowObject

Returns the value of attribute row.



4
5
6
# File 'lib/formotion/row_type/base.rb', line 4

def row
  @row
end

#tableViewObject

Returns the value of attribute tableView.



4
5
6
# File 'lib/formotion/row_type/base.rb', line 4

def tableView
  @tableView
end

Class Method Details

.field_bufferObject



6
7
8
9
10
11
12
# File 'lib/formotion/row_type/base.rb', line 6

def self.field_buffer
  if BW::Device.iphone? or App.window.size.width <= 320 or BW::Device.ios_version >= "7.0"
    20
  else
    64
  end
end

Instance Method Details

#_on_select(tableView, tableViewDelegate) ⇒ Object

method gets triggered when tableView(tableView, didSelectRowAtIndexPath:indexPath) in UITableViewDelegate is executed



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/formotion/row_type/base.rb', line 59

def _on_select(tableView, tableViewDelegate)
  # row class should call super and proceed if false is return (not handled here)
  if row.on_tap_callback
    # Not all row types will want to define on_tap, but call it if so
    if row.on_tap_callback.call(self.row) != false
      on_select(tableView, tableViewDelegate)
      true
    else
      false
    end
  else
    on_select(tableView, tableViewDelegate)
  end
end

#after_build(cell) ⇒ Object

called by the Row after all the setup and connections are made in #make_cell



49
50
# File 'lib/formotion/row_type/base.rb', line 49

def after_build(cell)
end

#after_deleteObject



101
102
# File 'lib/formotion/row_type/base.rb', line 101

def after_delete
end

#break_with_semaphore(&block) ⇒ Object



104
105
106
107
# File 'lib/formotion/row_type/base.rb', line 104

def break_with_semaphore(&block)
  return if @semaphore
  with_semaphore(&block)
end

#build_cell(cell) ⇒ Object

builder method for row cell specific implementation



42
43
44
45
# File 'lib/formotion/row_type/base.rb', line 42

def build_cell(cell)
  # implement in row class
  nil
end

#button?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/formotion/row_type/base.rb', line 22

def button?
  false
end

#cell_styleObject

RowCellBuilder uses this to instantiate the UITableViewCell.



27
28
29
# File 'lib/formotion/row_type/base.rb', line 27

def cell_style
  UITableViewCellStyleSubtitle
end

#cellEditingStyleObject

Sets the UITableViewCellEditingStyle



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

def cellEditingStyle
  row.deletable? ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleNone
end

#delete_rowObject



95
96
97
98
99
# File 'lib/formotion/row_type/base.rb', line 95

def delete_row
  tableView.beginUpdates
  tableView.deleteRowsAtIndexPaths [row.index_path], withRowAnimation:UITableViewRowAnimationBottom
  tableView.endUpdates
end

#done_editingObject



145
146
147
# File 'lib/formotion/row_type/base.rb', line 145

def done_editing
  NSLog "Please implement the done_editing method in your new cell type."
end

#indentWhileEditing?Boolean

Indents row while editing

Returns:

  • (Boolean)


37
38
39
# File 'lib/formotion/row_type/base.rb', line 37

def indentWhileEditing?
  row.indented?
end

#input_accessory_view(input_accessory) ⇒ Object

Creates the inputAccessoryView to show if input_accessory property is set on row. :done is currently the only supported option.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/formotion/row_type/base.rb', line 118

def input_accessory_view(input_accessory)
  case input_accessory
  when :done
    @input_accessory ||= begin
      tool_bar = UIToolbar.alloc.initWithFrame([[0, 0], [0, 44]])
      tool_bar.autoresizingMask = UIViewAutoresizingFlexibleWidth
      tool_bar.translucent = true

      left_space = UIBarButtonItem.alloc.initWithBarButtonSystemItem(
          UIBarButtonSystemItemFlexibleSpace,
          target: nil,
          action: nil)

      done_button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(
          UIBarButtonSystemItemDone,
          target: self,
          action: :done_editing)

      tool_bar.items = [left_space, done_button]

      tool_bar
    end
  else
    nil
  end
end

#on_delete(tableView, tableViewDelegate) ⇒ Object

called when the delete editing style was triggered tableView:commitEditingStyle:forRowAtIndexPath:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/formotion/row_type/base.rb', line 80

def on_delete(tableView, tableViewDelegate)
  if row.on_delete_callback
    row.on_delete_callback.call(self.row)
  end
  if row.remove_on_delete?
    row.section.rows.delete_at(row.index)
    row.section.refresh_row_indexes
    delete_row
    after_delete
  else
    row.value = nil
    self.tableView.reloadData
  end
end

#on_select(tableView, tableViewDelegate) ⇒ Object

Override in subclass



75
76
77
# File 'lib/formotion/row_type/base.rb', line 75

def on_select(tableView, tableViewDelegate)
  false
end

#update_cell(cell) ⇒ Object

Called on every tableView:cellForRowAtIndexPath: so keep implementation details minimal



54
55
# File 'lib/formotion/row_type/base.rb', line 54

def update_cell(cell)
end

#with_semaphore(&block) ⇒ Object



109
110
111
112
113
# File 'lib/formotion/row_type/base.rb', line 109

def with_semaphore(&block)
  @semaphore = true
  block.call
  @semaphore = false
end