[英]Change generic class type into subclass
我有这种方法:
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
CGPoint p = [gestureRecognizer locationInView:self.collectionView];
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:p];
if (indexPath == nil){
NSLog(@"couldn't find index path");
} else {
UICollectionViewCell* cell = [self.collectionView cellForItemAtIndexPath:indexPath];
if ([cell isKindOfClass:[MWGradeCell class]]){
NSLog(@"Yes");
//here I would like to get a custom property "cell.gradeLabel.text" that is specific to MWGradeCell
} else{
NSLog(@"No");
}
}
} else{
NSLog(@"ended");
}
}
它识别长按了UICollectionview的哪个UICollectionviewcell。 我的UICollectionView是用不同类型的子类UICollectionViewCells构建的,每个子类具有不同的属性。
现在,我只想获取特定单元格类型的属性,但是为此,我需要以某种方式将已识别的UICollectionViewCell更改为MWGradeCell。
不知道如何。 幸运的是,你们周围的人
我不确定我是否理解这个问题,但是您可以像这样强制转换单元格:
MWGradeCell* cell = (MWGradeCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
不记得是否真的需要(MWGradeCell *)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.