[英]Is it possible to get a cell's tag within the collectionview sizeForItemAtIndexPath delegate method?
[英]how can i create object of collectionview Cell in delegate sizeForItemAtIndexPath in swift
像在Objective中一样,我们可以如下获取CollectionViewCell的对象。 Swift有一些问题:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
DatasetCell *datasetCell = (DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath];
(DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath];
datasetCell.backgroundColor = [UIColor skyBlueColor];
}
我的快速代码是:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let datasetCell: DatasetCell = collectionView.cellForItemAtIndexPath(indexPath) as! DatasetCell
datasetCell.backgroundColor = UIColor.blueColor()
}
将该方法转换为快速方法,如下所示
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let datasetCell = collectionView(collectionView, cellForItemAtIndexPath: indexPath) as DatasetCell
datasetCell.backgroundColor = UIColor.blueColor()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.