0

I apologize for asking this question for the millionth time, I've read the other questions asking the same thing and I couldn't find the answer to my problem!

I made a UITapGestureRecognizer that is just not working, can someone take a look at my code and tell me what I'm doing wrong?

-(void) formatCellForY: (CGFloat) y{

CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat cellHeight = 70;

self.cell = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"Cell"]];
[self.cell setFrame:CGRectMake(20, y, screen.size.width - 40, cellHeight)];

self.cell.backgroundColor = [UIColor grayColor];
self.cell.userInteractionEnabled = YES;


self.cell.layer.shadowColor = [UIColor blackColor].CGColor;
self.cell.layer.shadowOffset = CGSizeMake(0, 1);
self.cell.layer.shadowOpacity = 1.0;
self.cell.layer.shadowRadius = 1.0;
self.cell.layer.cornerRadius = 1.0;
self.cell.clipsToBounds = NO;

UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, self.cell.frame.size.width - 40, cellHeight*(.4))];
titleLabel.numberOfLines = 32;
titleLabel.text = self.program.programName;
titleLabel.textColor = [UIColor whiteColor];
titleLabel.userInteractionEnabled = YES;
[self.cell addSubview:titleLabel];

UILabel *explanationLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, titleLabel.frame.origin.y + titleLabel.frame.size.height, titleLabel.frame.size.width, cellHeight - (titleLabel.frame.origin.y+ titleLabel.frame.size.height))];
explanationLabel.text = self.program.programDescription;
explanationLabel.numberOfLines = 3;
explanationLabel.textColor = [UIColor whiteColor];
explanationLabel.font = [UIFont systemFontOfSize:10.0];
explanationLabel.userInteractionEnabled = YES;
[self.cell addSubview:explanationLabel];

self.tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToInfoPage:)];
self.tap.numberOfTapsRequired = 1;
self.tap.numberOfTouchesRequired = 1;
self.tap.enabled = YES;
[self.cell addGestureRecognizer:self.tap];

NSLog(@"%@", self.tap);
}

Here is the code I used to add the cell to the screen.

for (CKRecord *record in records) {
        SBHProgram *program = [SBHProgram programForRecord:record];
        SBHCell *cell = [SBHCell cellForProgram:program andY:90*i];
        i++;
        [scrollView addSubview:cell.cell];
}
Neil Shweky
  • 893
  • 2
  • 10
  • 23

2 Answers2

0

You have missed adding self.cell to view. You are able to see labels with texts because you have added self.cell.clipsToBounds = NO;

All you have to do is add cell to view.

[self.view addSubview:self.cell]

nutz
  • 212
  • 1
  • 4
  • From which method are you calling formatCellForY: ? – nutz Mar 13 '16 at 17:20
  • The initializer of the class SBHCell. – Neil Shweky Mar 13 '16 at 17:29
  • It's possible that your scrollview is consuming the tap. Look at this http://stackoverflow.com/questions/17701323/uiscrollview-delayscontenttouches-issue delayContentTouches should solve your issue – nutz Mar 13 '16 at 17:37
  • Is it possible that it has something to do with what I'm assigning to the target to? I changed that and it started receiving the touch, just crashing when it does. – Neil Shweky Mar 15 '16 at 02:13
-1

PLEASE ADD

self.tap.delegate = self;
Sucharu Hasija
  • 1,096
  • 11
  • 23