In my collection view I need to select the first cell as soon as the view appear.
I have implemented didSelectItemAtIndexPath
and didDeselectItemAtIndexPath
When the cell is selected it shows a green border when is not selected the cell has a white border.
What I need to have is to start my app with the first cell with a green border.
I have tried to use selectItemAtIndexPath
however, the first cell is not showing the green border. What am I missing?
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let firstIndexPath = NSIndexPath(forItem: 0, inSection: 0)
frameCollectionView.selectItemAtIndexPath(firstIndexPath, animated: false, scrollPosition: .None)
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let frameCell = collectionView.cellForItemAtIndexPath(indexPath) as! FrameViewCell
frameCell.layer.borderWidth = 2
frameCell.layer.borderColor = UIColor.greenColor().CGColor
}
func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let frameCell = collectionView.cellForItemAtIndexPath(indexPath) as! FrameViewCell
frameCell.layer.borderWidth = 1
frameCell.layer.borderColor = UIColor.whiteColor().CGColor
}