0

I'm trying to change a specific CollectionViewCell once it's tapped on. I created a custom cell:

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

And I'm trying to access it like this:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:     (NSIndexPath *)indexPath
{
// Get the tapped cell
ProjectCell *projectCell = (ProjectCell *)[collectionView cellForItemAtIndexPath:indexPath];

// Run method
[projectCell editProject];
}

But I get the error while building:

No visible @interface for 'ProjectCell declares the selector 'editProject'

What am I doing wrong here?

Thanks a lot for help!

DipakSonara
  • 2,598
  • 3
  • 29
  • 34

1 Answers1

0

I think you need to declare your function in public space (in the header).

#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
Plokstorm
  • 44
  • 1
  • 7