Sha256: 5de367c2399842efefd8393256ee6b3dafb8c130ec0ec4b264560684847b496c

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

class ColorViewController < UITableViewController
  attr_accessor :colors
  
  def init
    self.colors = []
    self.title = "7 random colors"
    super
  end
  
  def viewDidLoad
    load_data
    super
  end
  
  def tableView(tableView, numberOfRowsInSection:section)
    self.colors.size
  end
  
  def tableView(tableView, cellForRowAtIndexPath:indexPath)
    cell = tableView.dequeueReusableCellWithIdentifier('Cell')
    cell ||= UITableViewCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier:'Cell')
    
    color = colors[indexPath.row]
    cell.textLabel.text = color.hex
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator
    cell
  end
  
  def tableView(tableView, willDisplayCell:cell, forRowAtIndexPath:indexPath)
    color = colors[indexPath.row]
    cell.backgroundColor = color.ui_color
  end
  
  def tableView(tableView, didSelectRowAtIndexPath:indexPath)
    navigationController.pushViewController(TagsViewController.alloc.initWithColor(colors[indexPath.row]), animated:true)
  end
  
  def load_data
    Color.random do |results|
      if results
        self.colors = results
      end
      tableView.reloadData
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
motion-resource-0.1.4 examples/Colr/app/color_view_controller.rb
motion-resource-0.1.3 examples/Colr/app/color_view_controller.rb
motion-resource-0.1.2 examples/Colr/app/color_view_controller.rb
motion-resource-0.1.1 examples/Colr/app/color_view_controller.rb
motion-resource-0.1.0 examples/Colr/app/color_view_controller.rb
motion-resource-0.0.2 examples/Colr/app/color_view_controller.rb
motion-resource-0.0.1 examples/Colr/app/color_view_controller.rb