Class: MotionForm::Base
- Inherits:
-
UITableView
- Object
- UITableView
- MotionForm::Base
- Defined in:
- lib/project/form/base.rb
Instance Attribute Summary collapse
-
#keyboard_avoiding_delegate ⇒ Object
readonly
Returns the value of attribute keyboard_avoiding_delegate.
Instance Method Summary collapse
- #build_section(title) ⇒ Object
- #did_begin_editing(notification) ⇒ Object
- #did_end_editing(notification) ⇒ Object
- #init ⇒ Object
- #listen ⇒ Object
- #notification_center ⇒ Object
- #numberOfSectionsInTableView(table_view) ⇒ Object
- #observers ⇒ Object
- #register_cells ⇒ Object
- #render ⇒ Object
- #render_values ⇒ Object
- #rows ⇒ Object
- #section(title = '') ⇒ Object
- #sections ⇒ Object
- #tableView(table_view, cellForRowAtIndexPath: index_path) ⇒ Object
- #valid? ⇒ Boolean
- #value_rows ⇒ Object
Instance Attribute Details
#keyboard_avoiding_delegate ⇒ Object (readonly)
Returns the value of attribute keyboard_avoiding_delegate.
5 6 7 |
# File 'lib/project/form/base.rb', line 5 def keyboard_avoiding_delegate @keyboard_avoiding_delegate end |
Instance Method Details
#build_section(title) ⇒ Object
52 53 54 55 56 |
# File 'lib/project/form/base.rb', line 52 def build_section(title) MotionForm::Section.new(title).tap do |section| sections << section end end |
#did_begin_editing(notification) ⇒ Object
26 27 28 29 30 |
# File 'lib/project/form/base.rb', line 26 def did_begin_editing(notification) unless window.nil? keyboard_avoiding_delegate.textFieldDidBeginEditing(notification.userInfo[:text_field]) end end |
#did_end_editing(notification) ⇒ Object
32 33 34 35 36 |
# File 'lib/project/form/base.rb', line 32 def did_end_editing(notification) unless window.nil? keyboard_avoiding_delegate.textFieldDidEndEditing(notification.userInfo[:text_field]) end end |
#init ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/project/form/base.rb', line 7 def init initWithFrame(frame, style: UITableViewStylePlain).tap do |f| f.register_cells f.separatorStyle = UITableViewCellSeparatorStyleNone f.translatesAutoresizingMaskIntoConstraints = false f.dataSource = self f.delegate = self @keyboard_avoiding_delegate = Motion::KeyboardAvoiding.new(f) listen end end |
#listen ⇒ Object
21 22 23 24 |
# File 'lib/project/form/base.rb', line 21 def listen observers << notification_center.addObserver(self, selector: 'did_begin_editing:', name: 'FormCellDidBeginEditing', object: nil) observers << notification_center.addObserver(self, selector: 'did_end_editing:', name: 'FormCellDidEndEditing', object: nil) end |
#notification_center ⇒ Object
42 43 44 |
# File 'lib/project/form/base.rb', line 42 def notification_center NSNotificationCenter.defaultCenter end |
#numberOfSectionsInTableView(table_view) ⇒ Object
68 69 70 |
# File 'lib/project/form/base.rb', line 68 def numberOfSectionsInTableView(table_view) sections.count end |
#observers ⇒ Object
38 39 40 |
# File 'lib/project/form/base.rb', line 38 def observers @observers ||= [] end |
#register_cells ⇒ Object
62 63 64 65 66 |
# File 'lib/project/form/base.rb', line 62 def register_cells MotionForm.registered_cells.each do |klass| registerClass(klass, forCellReuseIdentifier: klass::IDENTIFIER) end end |
#render ⇒ Object
120 121 122 123 124 |
# File 'lib/project/form/base.rb', line 120 def render notification_center.postNotificationName('FormWillRender', object: self, userInfo: nil) Hash[render_values] end |
#render_values ⇒ Object
126 127 128 |
# File 'lib/project/form/base.rb', line 126 def render_values value_rows.map { |row| [row.key, row.value] } end |
#rows ⇒ Object
101 102 103 |
# File 'lib/project/form/base.rb', line 101 def rows sections.map(&:rows).flatten end |
#section(title = '') ⇒ Object
46 47 48 49 50 |
# File 'lib/project/form/base.rb', line 46 def section(title = '') build_section(title).tap do |section| yield section end end |
#sections ⇒ Object
58 59 60 |
# File 'lib/project/form/base.rb', line 58 def sections @sections ||= [] end |
#tableView(table_view, cellForRowAtIndexPath: index_path) ⇒ Object
72 73 74 |
# File 'lib/project/form/base.rb', line 72 def tableView(table_view, numberOfRowsInSection: section_index) sections[section_index].rows.count end |
#valid? ⇒ Boolean
105 106 107 108 109 |
# File 'lib/project/form/base.rb', line 105 def valid? notification_center.postNotificationName('FormWillValidate', object: self, userInfo: nil) rows.select { |row| row.is_a? TextFieldRow }.all? { |row| row.valid? } end |
#value_rows ⇒ Object
130 131 132 |
# File 'lib/project/form/base.rb', line 130 def value_rows rows.select { |row| row.has_value? } end |