runeleaf
9/20/2012 - 5:10 AM

GridViewController

GridViewController

class GridViewController < AQGridViewController

  def viewDidLoad

    @data = ['001.jpg', '002.jpg', '003.jpg', '004.jpg', '005.jpg', '006.jpg', '007.jpg', '008.jpg', '009.jpg', '010.jpg']

    @grid_view = AQGridView.alloc.initWithFrame(self.view.bounds)
    @grid_view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight
    @grid_view.autoresizesSubviews = true
    @grid_view.delegate = self
    @grid_view.dataSource = self

    self.view.addSubview @grid_view
    @grid_view.reloadData
  end

  def numberOfItemsInGridView(grid_view)
    @data.length
  end

  def gridView(grid_view, didSelectItemAtIndex:index)
    grid_view.deselecteItemAtIndex(index, animated:true)
    nil
  end

  def portraitGridCellSizeForGridView(grid_view)
    [70, 70]
  end

  def gridView(grid_view, cellForItemAtIndex:index)
    @reuse_identifier ||= "GRID_CELL_IDENTIFIER"
    cell = grid_view.dequeueReusableCellWithIdentifier(@reuse_identifier)
    unless cell
      cell = PhotoGridViewCell.alloc.initWithFrame([[0, 0], [60, 60]], reuseIdentifier:@reuse_identifier)
    end

    cell.image_view.image = UIImage.imageNamed(@data[index])

    cell
  end

end