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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:35:32+00:00 2026-05-13T08:35:32+00:00

I have a little problem resigning the keyboard. I have a table with two

  • 0

I have a little problem resigning the keyboard. I have a table with two sections. In the second section, I load the class stationenStartCellNumber which has a UITextField.

When I press anywhere outside of the UITextField, I want the keyboard to resign as first responder, and thereby closing the keyboard. It works perfectly inside of my cell, but not on my UITableView.

This is my code:
stationenViewController.h:

#import <UIKit/UIKit.h>
#import "stationenStartCell.h"
#import "stationenAppDelegate.h"

@interface stationenViewController : UIViewController  <UITableViewDelegate, UITableViewDataSource> {
    IBOutlet UITableView *theTable;

    NSString *stationenPlistPath;
}

@property (nonatomic, retain) UITableView *theTable;
@property (nonatomic, retain) IBOutlet NSString *stationenPlistPath;

- (void)copyStationPlist;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

@end

stationenViewController.m:

#import "stationenViewController.h"
#import "chooseStationView.h"
#import "chooseArrDepView.h"
#import "stationenStartCellNumber.h"

@implementation stationenViewController

@synthesize theTable;
@synthesize stationenPlistPath;

- (void)viewWillAppear:(BOOL)animated {
    [theTable reloadData];

    [[[self navigationController] navigationBar] setAlpha:1];

    [super viewWillAppear:animated];
}

- (void)viewDidLoad
{
    NSArray *bikePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *bikeDocumentsDirectory = [bikePath objectAtIndex:0];
    stationenPlistPath = [bikeDocumentsDirectory stringByAppendingPathComponent:@"stationen.plist"];

    if(![[NSFileManager defaultManager] fileExistsAtPath:stationenPlistPath])
    {
        [self copyStationPlist];
    }

    [super viewDidLoad];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{   
    NSUInteger returnInt = 2;

    if (section == 1)
    {
        returnInt = 1;
    }

    return returnInt;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    NSString *returnString = [[NSString alloc] init];

    if(section == 0)
    {
        returnString = @"Search station details";
    }
    else if (section == 1)
    {
        returnString = @"Search train number";
    }

    return returnString;
}   

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        static NSString *CellIdentifier = @"stationenStartCellID";
        stationenStartCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

        if (cell == nil){
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"stationenStartCell" owner:nil options:nil];

            for(id currentObject in topLevelObjects)
            {
                if([currentObject isKindOfClass:[stationenStartCell class]])
                {
                    cell = (stationenStartCell *)currentObject;
                    break;
                }
            }
        }

        [[cell theBackground] setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"stationenStartCell_Background.png"]]];
        [[cell theImage] setImage:[UIImage imageNamed:@"icon_checkMark.png"]];

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];

        if(indexPath.row % 4 == 0)
        {
            [[cell cellName] setText:NSLocalizedString(@"Choose station", @"Main page")];
            [[cell chosenValue] setText:[prefs valueForKey:@"chosenStation"]];

            NSLog(@"Log info: %@", [prefs valueForKey:@"chosenStation"]);

            if([[prefs valueForKey:@"chosenStation"] isEqualToString:@""] || [prefs valueForKey:@"chosenStation"] == nil)
            {
                [[cell theImage] setAlpha:0.2];
            }
            else {
                [[cell theImage] setAlpha:1];
            }
        }

        if(indexPath.row % 4 == 1)
        {
            NSString *searchType = [prefs valueForKey:@"searchType"];
            NSString *theValue = @"";
            if([searchType isEqualToString:@"0"])
            {
                theValue = NSLocalizedString(@"Arrivals", @"Main page");
            }
            else if([searchType isEqualToString:@"1"])
            {
                theValue = NSLocalizedString(@"Departures", @"Main page");
            }

            if([theValue isEqualToString:@""])
            {
                [[cell theImage] setAlpha:0.2];
            }
            else {
                [[cell theImage] setAlpha:1];
            }

            [[cell cellName] setText:NSLocalizedString(@"Choose departure/arrival", @"Main page")];
            [[cell chosenValue] setText:theValue];
        }

        [UIView commitAnimations];

        return cell;
    }
    else if (indexPath.section == 1)
    {
        static NSString *CellIdentifier = @"stationenStartCellNumber";
        stationenStartCellNumber *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil){
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"stationenStartCellNumber" owner:nil options:nil];

            for(id currentObject in topLevelObjects)
            {
                if([currentObject isKindOfClass:[stationenStartCellNumber class]])
                {
                    cell = (stationenStartCellNumber *)currentObject;
                    break;
                }
            }
        }

        [[cell theLabel] setText:@"Tåg nr:"];

        return cell;
    }

    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];

    if (indexPath.section == 0)
    {
        if(indexPath.row == 0)
        {
            chooseStationView *chooseStationViewController = [[chooseStationView alloc] initWithNibName:@"chooseStationView" bundle:nil];
            [[self navigationController] pushViewController:chooseStationViewController animated:YES];
            [chooseStationViewController release], chooseStationViewController = nil;
        }
        else {
            chooseArrDepView *chooseArrDepViewController = [[chooseArrDepView alloc] initWithNibName:@"chooseArrDepView" bundle:nil];
            [[self navigationController] pushViewController:chooseArrDepViewController animated:YES];
            [chooseArrDepViewController release], chooseArrDepViewController = nil;
        }
    }
    else {
        [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [theTable becomeFirstResponder];
    [super touchesBegan:touches withEvent:event];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait || 
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

-(void)copyStationPlist
{
    NSString* bikesDictionaryPath = [[NSBundle mainBundle] pathForResource:@"stations" ofType:@"plist"];
    NSDictionary* bikesDictionary = [[NSDictionary alloc] initWithContentsOfFile:bikesDictionaryPath];

    NSArray *bikePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *bikeDocumentsDirectory = [bikePath objectAtIndex:0];
    NSString *path = [bikeDocumentsDirectory stringByAppendingPathComponent:@"stations.plist"];

    NSString * error;
    NSData * data = [NSPropertyListSerialization dataFromPropertyList:bikesDictionary format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
    [data writeToFile:path atomically:YES];
}

- (void)dealloc {
    [super dealloc];
}

@end

Offcourse, the touchesBegan code does not work on a tableView because that one takes over. How can I resign the keyboard?

  • 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-13T08:35:32+00:00Added an answer on May 13, 2026 at 8:35 am

    You can create an invisible UIButton with an action to resign the keyboard.

    Also, you will want to make sure to scroll your table view so that the keyboard does not cover your text field.

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

Sidebar

Related Questions

I have a little problem with a Listview. I can load it with listview
I have a little problem with a simple vbScript. The script has to run
I have this little problem, that I cannot figure out which arguments to pass
i have little problem how i will recognize which item was clicked with OnClickEvent.
Hey most of my issue has been solved but i have little problem This
i have little problem with boost::asio library. My app receive and process data asynchronously,
I have little problem with a replacement of a little part in an url.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,
I have a little problem with some jquery and http://www.mikage.to/jquery/jquery_history_noc.html The function works great,
I have a little problem where I would like to insert a svn diff

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.