我试图在点击后更改特定的CollectionViewCell
。我创建了一个自定义单元格:
projectCell.h:
#import <UIKit/UIKit.h>
@interface ProjectCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UILabel *projectLabel;
@property (weak, nonatomic) IBOutlet UILabel *projectCount;
@property (weak, nonatomic) IBOutlet UITextField *projectTextField;
@end
projectCell.m:
#import "ProjectCell.h"
#import "QuartzCore/CALayer.h"
@implementation ProjectCell
{
BOOL editMode;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)awakeFromNib {
// Custom initial code
}
-(void)editProject {
if (editMode == YES) {
// disable editMode and update the project cell
editMode = NO;
_projectTextField.hidden = YES;
} else if (editMode == NO) {
// Enable editMode and update the project cell
editMode = YES;
_projectTextField.hidden = NO;
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
我试图像这样访问它:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath: (NSIndexPath *)indexPath
{
// Get the tapped cell
ProjectCell *projectCell = (ProjectCell *)[collectionView cellForItemAtIndexPath:indexPath];
// Run method
[projectCell editProject];
}
但是我在构建时遇到错误:
没有可见的@interface for&#39; ProjectCell声明选择器&#39; editProject&#39;
我在这里做错了什么?
非常感谢您的帮助!
答案 0 :(得分:0)
我认为您需要在公共空间(标题中)声明您的功能。
#import <UIKit/UIKit.h>
@interface ProjectCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UILabel *projectLabel;
@property (weak, nonatomic) IBOutlet UILabel *projectCount;
@property (weak, nonatomic) IBOutlet UITextField *projectTextField;
-(void)editProject;
@end