Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conflict in UIGestureRecognizer in custom cell and dequeueCellWithIdentifier

I have a custom UITableViewCell (.h, .m, .xib) registered in a UITableView.

Now i need to use a custom UIImage inside the cell and attach to it a Gesture Recognizer (I can't use a UIButton). The problem is that if it at runtime I get a

Terminating app due to uncaught exception  'NSInternalInconsistencyException', 
reason: 'invalid nib registered for identifier (CustomCell) - 
nib must contain exactly one top level object which must be a UITableViewCell instance'

If i remove the gesture the cell works correctly, i believe it's a cocoa bug, i will now try to instantiate it programmatically, but i guess the problem is that the gesture recognizer is on the same herarchy level of the TableViewCell in the xib

enter image description here

do you know other interface builder workaround?

like image 398
jalone Avatar asked Aug 12 '15 12:08

jalone


1 Answers

Enabling user interaction on the UIImage and adding programmatically a gesture recognizer in the awakeFromNib works

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[self.imagePicture addGestureRecognizer:tap];

But i'd like to know the reason why it is not working rather. I will wait to accept.

like image 190
jalone Avatar answered Oct 16 '22 00:10

jalone