Class: MotionPrime::TableDelegate

Inherits:
Object
  • Object
show all
Includes:
DelegateMixin
Defined in:
motion-prime/sections/table/table_delegate.rb

Direct Known Subclasses

FormDelegate

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DelegateMixin

#clear_delegated, #delegated_by

Constructor Details

#initialize(options) ⇒ TableDelegate

Returns a new instance of TableDelegate.



5
6
7
8
# File 'motion-prime/sections/table/table_delegate.rb', line 5

def initialize(options)
  self.table_section = options[:section].try(:weak_ref)
  @section_instance = table_section.to_s
end

Instance Attribute Details

#table_sectionObject

Returns the value of attribute table_section.



4
5
6
# File 'motion-prime/sections/table/table_delegate.rb', line 4

def table_section
  @table_section
end

Instance Method Details

#init_pull_to_refreshObject

def dealloc

pp 'Deallocating table_delegate for ', @section_instance
super

end



15
16
17
18
19
20
# File 'motion-prime/sections/table/table_delegate.rb', line 15

def init_pull_to_refresh
  return unless block = table_section.class.pull_to_refresh_block
  table_section.add_pull_to_refresh do
    table_section.instance_eval(&block)
  end
end

#numberOfSectionsInTableView(table) ⇒ Object



22
23
24
# File 'motion-prime/sections/table/table_delegate.rb', line 22

def numberOfSectionsInTableView(table)
  table_section.number_of_groups(table)
end

#scrollViewDidEndDecelerating(scroll) ⇒ Object



68
69
70
# File 'motion-prime/sections/table/table_delegate.rb', line 68

def scrollViewDidEndDecelerating(scroll)
  table_section.scroll_view_did_end_decelerating(scroll)
end

#scrollViewDidEndDragging(scroll, willDecelerate: will_decelerate) ⇒ Object



72
73
74
# File 'motion-prime/sections/table/table_delegate.rb', line 72

def scrollViewDidEndDragging(scroll, willDecelerate: will_decelerate)
  table_section.scroll_view_did_end_dragging(scroll, willDecelerate: will_decelerate)
end

#scrollViewDidScroll(scroll) ⇒ Object



60
61
62
# File 'motion-prime/sections/table/table_delegate.rb', line 60

def scrollViewDidScroll(scroll)
  table_section.scroll_view_did_scroll(scroll)
end

#scrollViewWillBeginDragging(scroll) ⇒ Object



64
65
66
# File 'motion-prime/sections/table/table_delegate.rb', line 64

def scrollViewWillBeginDragging(scroll)
  table_section.scroll_view_will_begin_dragging(scroll)
end

#tableView(table, heightForHeaderInSection: group) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'motion-prime/sections/table/table_delegate.rb', line 26

def tableView(table, cellForRowAtIndexPath: index)
  cur_call_time = Time.now.to_f
  cur_call_offset = table.contentOffset.y
  if @prev_call_time
    time_delta = cur_call_time - @prev_call_time
    offset_delta = cur_call_offset - @prev_call_offset
    @deceleration_speed = offset_delta/time_delta
  end
  @prev_call_time = cur_call_time
  @prev_call_offset = cur_call_offset

  table_section.cell_for_index(table, index)
end