Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I'm getting gesture recognizers cannot be used on prototype objects?

Tags:

ios

storyboard

I'm getting the above error from storyboard when I dropped a UITapGestureRecognizer inside a UIView which is inside a UITableViewCell in my scene.

Any idea why I'm getting this error ?

like image 454
Tushar Avatar asked Feb 19 '23 08:02

Tushar


1 Answers

I'm not sure why the restriction is in place but I know why you are getting it the error.

When you design a UITableViewCell in StoryBoard you are only designing a prototype object. i.e. the object may never actually exist. It only gets ACTUALLY created in tableView:cellForRowAtIndexPath:

What might be a better approach is to create the gestureRecognizer when you configure the cell in code. This way you won't have this restriction.

I'd also possibly look at whether you actually need it? If it is just for a single tap with one finger then you may be better off coding the touchesEnded or just using a UIButton instead.

like image 136
Fogmeister Avatar answered Feb 20 '23 20:02

Fogmeister