允许在swift中获取sizeForItemAtIndexPath中的集合视图Cell对象

时间:2015-12-02 05:19:53

标签: ios swift

就像在Objective中一样,我们可以获得Collection View Cell的对象,如下所示。有一些Swift的问题

-(void)collectionView:(UICollectionView *)collectionView 
   didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

DatasetCell *datasetCell = 
  (DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath];

[datasetCell replaceHeaderGradientWith:[UIColor skyBlueHeaderGradient]];
datasetCell.backgroundColor = [UIColor skyBlueColor]; }

1 个答案:

答案 0 :(得分:2)

试试这个:

 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

let datasetCell =  collectionView(collectionView, cellForItemAtIndexPath: indexPath) as DatasetCell
datasetCell.backgroundColor = UIColor.blueColor()

}