in rubymotion how to manually invoke table method

53 views Asked by At

I'm using a UICollectionViewController and I'm trying to set an item as selected automatically (ie. previously selected options). If I attempt to set when I'm setting the cells data

def collectionView(view, cellForItemAtIndexPath: index_path)  

  //create the cell etc.. then
  cell.selected = true
  cell.update(index_path.row)
end

I get NoMethodError for selected. However this works from the normal select/deselect methods.

  def collectionView(view, didSelectItemAtIndexPath: index_path)
  cell = view.cellForItemAtIndexPath(index_path)
  cell.selected = true     
end

Any ideas on how can I automatically preselect a cell?

Thanks,

1

There are 1 answers

0
vacawama On BEST ANSWER

To preselect a cell in a Collection View named myColView, call:

indexPath = NSIndexPath.indexPathForItem(1, inSection: 0)
myColView.selectItemAtIndexPath(indexPath, animated: false, scrollPosition: 0)

This method does not cause any selection-related delegate methods to be called.