Like in Objective we can get object of CollectionViewCell as below. have some issue with Swift:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
DatasetCell *datasetCell = (DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath];
(DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath];
datasetCell.backgroundColor = [UIColor skyBlueColor];
}
my swift code is :
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let datasetCell: DatasetCell = collectionView.cellForItemAtIndexPath(indexPath) as! DatasetCell
datasetCell.backgroundColor = UIColor.blueColor()
}
To translate that method into swift it would look like this
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let datasetCell = collectionView(collectionView, cellForItemAtIndexPath: indexPath) as DatasetCell
datasetCell.backgroundColor = UIColor.blueColor()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.