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 661333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:15:20+00:00 2026-05-13T23:15:20+00:00

Similar to this question I have a custom subclass of UITableViewCell that has a

  • 0

Similar to this question I have a custom subclass of UITableViewCell that has a UITextField. Its working fine except the keyboard for doesn’t go away when the user touches a different table view cell or something outside the table. I’m trying to figure out the best place to find out when something outside the cell is touched, then I could call resignFirstResponder on the text field.

If the UITableViewCell could receive touch events for touches outside of its view then it could just resignFirstResponder itself but I don’t see any way to get those events in the cell.

EDIT: I tried this (below) in my UITableViewCell subclass but it doesn’t work, I think because touchesBegan:withEvent: doesn’t get called if the event was handled by a control. I think I need to catch the events before they get send down the responder chain somehow.

The solution I’m considering is to add a touchesBegan:withEvent: method to the view controller. There I could send a resignFirstResponder to all tableview cells that are visible except the one that the touch was in (let it get the touch event and handle it itself).

Maybe something like this pseudo code:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    CGPoint touchPoint = // TBD - may need translate to cell's coordinates

    for (UITableViewCell* aCell in [theTableView visibleCells]) {
        if (![aCell pointInside:touchPoint withEvent:event]) {
             [aCell resignFirstResponder];
        }
    }
}

I’m not sure if this is the best way to go about this. There doesn’t seem to be any way for the tableviewcell itself to receive event notifications for events outside its view.

EDIT2: I thought I had an answer (I even posted it as an answer) using hitTest:withEvent: but that didn’t work out. It doesn’t always get called. 🙁

  • 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-05-13T23:15:20+00:00Added an answer on May 13, 2026 at 11:15 pm

    [Edited: removed previous attempt which didn’t always work, this one does]

    OK, I finally figured a solution that fully works. I subclassed UITableView and overrode the hitTest:withEvent: method. It gets invoked for all touches anywhere in the table view, the only other possible touches are in the navbar or keyboard and the tableview’s hitTest doesn’t need to know about those.

    This keeps track of the active cell in the table view, and whenever you tap a different cell (or non-cell) it sends a resignFirstResponder to the cell going inactive, which gives it a chance to hide its keyboard (or its datepicker).

    -(UIView*) hitTest:(CGPoint)point withEvent:(UIEvent*)event
    {
        // check to see if the hit is in this table view
        if ([self pointInside:point withEvent:event]) {
            UITableViewCell* newCell = nil;
    
            // hit is in this table view, find out 
            // which cell it is in (if any)
            for (UITableViewCell* aCell in self.visibleCells) {
                if ([aCell pointInside:[self convertPoint:point toView:aCell] withEvent:nil]) {
                    newCell = aCell;
                    break;
                }
            }
    
            // if it touched a different cell, tell the previous cell to resign
            // this gives it a chance to hide the keyboard or date picker or whatever
            if (newCell != activeCell) {
                [activeCell resignFirstResponder];
                self.activeCell = newCell;   // may be nil
            }
        }
    
        // return the super's hitTest result
        return [super hitTest:point withEvent:event];   
    }    
    

    In my UITableViewCell subclasses that have a UITextField, I add the following code to get rid of the keyboard (or date picker, which slides up just like the keyboard):

    -(BOOL)resignFirstResponder
    {   
        [cTextField resignFirstResponder];  
        return [super resignFirstResponder];
    }
    

    Yay!

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

Sidebar

Related Questions

Similar to this question: link However I have already mastered that. My problem is
This is similar to this question, except the code is already written. I have
I have a custom UITableViewCell nib that has an image on the left side
I have a similar situation to this question . I have a custom sequential
I have a question which is slightly similar to this question on stackoverflow std::cin.clear()
I have checked this similar question, but the suggestions did not solve my problem:
I have a question similar to this: how to manually assign imagefield in Django
I have a similar question to this one However, I have a less strict
I have asked a question similar to this in the past but this is
i have a table which looks similar to this <asp:TableRow><asp:TableCell>Question 1</asp:TableCell><asp:TableCell ID =Question1Text></asp:TableCell></asp:TableRow> <asp:TableRow><asp:TableCell

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.