在我的集合视图中,我需要在视图出现后立即选择第一个单元格。
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.
我需要的是从第一个带有绿色边框的单元格开始我的应用程序。
但是,我尝试使用selectItemAtIndexPath
,第一个单元格没有显示绿色边框。我错过了什么?
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
}