2017-05-28 119 views
0

我有這樣的方法:更改泛型類類型爲子

-(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。

不知道如何。幸運的是,你人身邊

回答

0

我不知道如果我理解的問題,但你可以只投細胞,如:

MWGradeCell* cell = (MWGradeCell *)[self.collectionView cellForItemAtIndexPath:indexPath]; 

不記得,如果(MWGradeCell *)是真的有必要

+0

謝謝,我做那。但該應用程序墜毀在不同的類。然後我嘗試了上面的代碼。我應該結合這兩種方法。是的,(MWGradeCell *)是必需的,否則cellforitematindexpath將不起作用。 – Sjakelien