Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9271699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:41:04+00:00 2026-06-18T15:41:04+00:00

I have strange issue – when I register TapGestureRecognizer in the cellForRowAtIndexPath method it

  • 0

I have strange issue – when I register TapGestureRecognizer in the cellForRowAtIndexPath method it works perfect, but when I register TapGestureRecognizer in cell’s initWithStyle method tap recognition doesn’t work, breakpoint doesn’t hit in handler.

The following works.

I have created custom table view cell with corresponding xib file and registered it.

[self.tableView registerNib:[UINib nibWithNibName:@"MyCell"
                                               bundle:[NSBundle mainBundle]]
         forCellReuseIdentifier:@"cell"];
...

and in the cellForRowAtIndexPath 
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
...
 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                          action:@selector(didTapCell:)];
    [tap setNumberOfTapsRequired:1];
    [cell addGestureRecognizer:tap];

The following doesn’t work

@implementation MyCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleCellTap:)];
        [tgr setDelegate:self];
        [tgr setNumberOfTapsRequired:1];
        [tgr setNumberOfTouchesRequired:1];

        [self addGestureRecognizer:tgr];
        //[self.contentView addGestureRecognizer:tgr]; also doesn't work
    }
    return self;
}

I can leave the working solution, but I want to move the gesture recognition to cell initialization and fire tap event through my delegate.

Why is tap recognition not working if I’m registering recognizer in the cell initialization?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:41:06+00:00Added an answer on June 18, 2026 at 3:41 pm

    You have registered a xib for a particular cell identifier. Now the tableview will automatically instantiate a cell for you if needed (when you call dequeReusableCell…) but the initWithStyle:reuseIdentifier method does not get called, so your gesture recognizer is never created/added.

    If you do need to ‘init’ stuff when using registered xib(s), override the awakeFromNib in your custom cell class and put your code there. I usually put my ‘init’ code in a separate method and call it from both initWithStyle and awakeFromNib overrides.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very strange issue with the tableview: I have a table cell
I have a strange issue. I am using google authentication and this works on
I have strange issue with nested left-joins in postgresql... It's hard to explain, but
I have strange issue. ModelState has error. But I don`t have a rule for
I have a strange issue with to_json method in my Rails 3 app. (well
I have a strange issue going on. It may be server related, but I
I have a strange issue. Here is the error message: Call to undefined method
I have a strange issue where I set values in a parent class but
I have a strange issue: I am using SPContext.Current.Web in a .aspx page, but
Have following strange issue, have 7 lines (same classes) but after 2 lines it's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.