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

  • Home
  • SEARCH
  • 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 8831245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:16:01+00:00 2026-06-14T08:16:01+00:00

I’m learning obj-c and gave myself a simple task of creation an app that

  • 0

I’m learning obj-c and gave myself a simple task of creation an app that has 2 uitextfields, label & button (button summarizes 2 numbers and shows the result in label). I made this app but I haven’t figured out how to make textfields interact with “done” button & “numbers only” together.

Below is my code:

#import UIKit/UIKit.h

@interface ViewController : UIViewController

@property IBOutlet UILabel *label;
@property IBOutlet UITextField *textField1;
@property IBOutlet UITextField *textField2;
@property NSInteger textFieldInt1, textFieldInt2;
@property NSString *textFieldStr1, *textFieldStr2;

-(IBAction)button:(id)sender;
-(IBAction)hideKeyboard:(id)sender;

@end


#import "ViewController.h"

@interface ViewController ()
@end

@implementation ViewController

@synthesize label, textField1, textField2, textFieldInt1, textFieldInt2, textFieldStr1, textFieldStr2;

-(IBAction)button:(id)sender {
    textFieldInt1=[textField1.text integerValue];
    textFieldInt2=[textField2.text integerValue];
    label.text=[NSString stringWithFormat: @"%d", textFieldInt1+textFieldInt2];
    [self.view endEditing:YES];
}



- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    [self.textField1 setReturnKeyType:UIReturnKeyDone];
    [self.textField2 setReturnKeyType:UIReturnKeyDone];

}

-(IBAction)hideKeyboard:(id)sender
{
    [self.view endEditing:YES];
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range     replacementString:(NSString *)string {
    if(![string intValue] && ![string isEqualToString:@""] && ![string isEqualToString:@"0"])
    {
    return NO;
    } else {
    return YES;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
    [super touchesBegan:touches withEvent:event];
}


@end

Also I connected (in storyboard) both textFields to hideKeyboard (didEndOnExit), and button to button (touchUpInside) and all outlets (textfields, button, label).

The problem is: numbers only input doesn’t work with done. If I use delegate (new referencing outlet in storyboard connected to both textfields) I get numbers only input in textfields but the done button doesn’t work (when I press it on the iPhone nothing happens). If I don’t use delegate I get all characters input but done works fine (when I press it iPhone keyboard hides).

Any suggestions what I may be doing wrong here?

  • 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-14T08:16:02+00:00Added an answer on June 14, 2026 at 8:16 am

    Implement the UITextFieldDelegate method:

    // This is how we get rid of the keyboard.
    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
        //Do whatever you need to to save etc...
        [textField resignFirstResponder];
        return NO;
    }
    

    This tells the keyboard to hide when the done button is pressed.
    Be sure to set your view controller as the textfields’ delegate:
    myTextField.delegate = self;
    (probably in viewDidLoad)

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I

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.