Sha256: 2f79c99b83d42fff6cd53f506dc8ff137bbecfacb3a2776ba5cb8d63b1fdc1d0

Contents?: true

Size: 1.1 KB

Versions: 23

Compression:

Stored size: 1.1 KB

Contents

# ** What is a TableSection? **
#
# "TableSection" is a "Section" which have some sugar to work with UITableViews.

# ** Create a Cell Section. **
#
# Inherit it from `Prime::Section`. 
# 
# Each element inside this section will be part of one cell.

class FooCellSection < Prime::Section
  element :title, text: proc { model[:title] }
end

# ** Create a Table Section. **
#
# Just inherit it from `Prime::TableSection`. 
#
# The key method which should be created is `table_data`. It should return array of any sections.

class FooTableSection < Prime::TableSection
  def table_data
    my_foo_items.map do |fruit_name|
      model = {title: fruit_name}
      FooCellSection.new(model: model)
    end
  end

  def my_foo_items
    %w[Orange Apricot Banana]
  end
end

# ** Render table to a Screen. **
#

class FooScreen < Prime::Screen
  def render
    @main_section = FooTableSection.new(screen: self)
    @main_section.render
  end
end

# ** Style it. **
#
# Of course, don't forget to add styles for table cells.

Prime::Styles.define :foo_cell do
  style :title,
    left: 20,
    top: 5,
    width: 200,
    height: 20
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
motion-prime-0.9.6 doc/code/tables.rb
motion-prime-0.9.5 doc/code/tables.rb
motion-prime-0.9.4 doc/code/tables.rb
motion-prime-0.9.3 doc/code/tables.rb
motion-prime-0.9.2 doc/code/tables.rb
motion-prime-0.9.1 doc/code/tables.rb
motion-prime-0.9.0 doc/code/tables.rb
motion-prime-0.8.12 doc/code/tables.rb
motion-prime-0.8.11 doc/code/tables.rb
motion-prime-0.8.10 doc/code/tables.rb
motion-prime-0.8.9 doc/code/tables.rb
motion-prime-0.8.8 doc/code/tables.rb
motion-prime-0.8.7 doc/code/tables.rb
motion-prime-0.8.6 doc/code/tables.rb
motion-prime-0.8.5 doc/code/tables.rb
motion-prime-0.8.4 doc/code/tables.rb
motion-prime-0.8.3 doc/code/tables.rb
motion-prime-0.8.2 doc/code/tables.rb
motion-prime-0.8.1 doc/code/tables.rb
motion-prime-0.8.0 doc/code/tables.rb