0

我無法調用駐留在我的UICollectionViewCell的委託方法...調用委託方法UICollectionViewCell

在我FOFPhotoCell.mi有以下代碼:

-(void)fadeOutLabels 
{ 
    NSLog(@"fadeOutLabels was called"); 
    [UIView animateWithDuration:1.0 
          delay:0.0 /* do not add a delay because we will use performSelector. */ 
         options:UIViewAnimationOptionCurveEaseIn 
        animations:^ { 
         self.titleLabel.alpha = 0.0; 
        } 
        completion:^(BOOL finished) { 
         [self.titleLabel removeFromSuperview]; 

        }]; 

} 

在FOFPhotoCell.h有定義如下:

@protocol FOFPhotoCellDelegate <NSObject> 

@required 
-(void)fadeOutLabels; 

@end 


@interface FOFPhotoCell : UICollectionViewCell { 
    id delegate; 
} 


@property (nonatomic, weak) id<FOFPhotoCellDelegate> delegate; 
在我FOFPhotosViewController.h

@interface FOFPhotosViewController : UICollectionViewController <FOFPhotoCellDelegate> 


@end 

,最後,我FOFPhotosViewController.m:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 
    FOFPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"photo" forIndexPath:indexPath]; 

    NSArray *photosArray = [self.dishes valueForKeyPath:@"avatar_url"]; 
    NSArray *nameArray = [self.dishes valueForKeyPath:@"name"]; 


// NSLog(@"photoURL %@", _responseDictionary); 
    cell.backgroundColor = [UIColor lightGrayColor]; 
    [cell.imageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"****",[photosArray objectAtIndex: indexPath.row]]]]; 
    cell.titleLabel.text = [NSString stringWithFormat:@"%@", [nameArray objectAtIndex:indexPath.row]]; 




    UILongPressGestureRecognizer *tapAndHold = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(fadeOutLabels)]; 

    tapAndHold.minimumPressDuration = 0.5; 
    [self.collectionView addGestureRecognizer:tapAndHold]; 



    [self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]]; 

    return cell; 
} 

但是這使得應用程序崩潰:-[FOFPhotosViewController fadeOutLabels]: unrecognized selector sent to instance

我似乎無法弄清楚這一個,所以我會很感激一些幫助!讓我知道是否需要更多的代碼。

在此先感謝 克里斯

+0

爲什麼downvote:

假設一切是正確的,如下改變這一行?請解釋一下,以便我可以在下次更好地提出我的問題... – Chris

回答

0

fadeOutLables是你的細胞的方法,而不是你的視圖控制器。

錯誤消息是正確的。

UILongPressGestureRecognizer *tapAndHold = [[UILongPressGestureRecognizer alloc] initWithTarget:cell action:@selector(fadeOutLabels)]; 
+0

That works @Hermann!非常感謝你 – Chris