Ios 调用委托方法UICollectionViewCell
调用驻留在UICollectionViewCell中的委托方法时遇到问题 在我的FOFPhotoCell.m中,我有以下代码:Ios 调用委托方法UICollectionViewCell,ios,objective-c,delegates,uicollectionview,uicollectionviewcell,Ios,Objective C,Delegates,Uicollectionview,Uicollectionviewcell,调用驻留在UICollectionViewCell中的委托方法时遇到问题 在我的FOFPhotoCell.m中,我有以下代码: -(void)fadeOutLabels { NSLog(@"fadeOutLabels was called"); [UIView animateWithDuration:1.0 delay:0.0 /* do not add a delay because we will use perf
-(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 fadeOutLabels]:无法识别的选择器发送到实例
我似乎无法理解这一点,因此我非常感谢您的帮助!如果需要更多的代码,请告诉我
提前谢谢
Chris
淡出选项
是单元格的一种方法,而不是视图控制器的一种方法
错误消息刚好正确
假设其他一切都是正确的,将此行更改如下:
UILongPressGestureRecognizer *tapAndHold = [[UILongPressGestureRecognizer alloc] initWithTarget:cell action:@selector(fadeOutLabels)];
为什么要投否决票?请解释一下,以便下次我能更好地提问。。。
-(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;
}
UILongPressGestureRecognizer *tapAndHold = [[UILongPressGestureRecognizer alloc] initWithTarget:cell action:@selector(fadeOutLabels)];