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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:18:34+00:00 2026-06-01T17:18:34+00:00

I am new to objective c,so plz me help with this… i have used

  • 0

I am new to objective c,so plz me help with this…
i have used three textfields in the interface builder
textfield1 inputs the first number
textfield2 inputs the second number

and i have created a button called sum which will calculate the sum
and textfield(ans) will display the result

.h file code

 {
      IBOutlet UITextfield txtfield1;
      IBOutlet UITextfield txtfield2;
      IBOutlet UITextfield ans;
 }
 -(IBAction)add;

.m file code

 -(IBAction)add
  {
      int result=[txtfield1.text intValue]+[txtfield2.text intValue];
      ans.text=[NSString StringWithFormat:@"%d",result];
  }

The program runs fine,but i want only integer values to be entered in the textfield,if i enter alphabets and click on the sum button i get 0 as the ans,what can i do so that user gets an error when he inputs alphabets..thanks..

  • 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-01T17:18:36+00:00Added an answer on June 1, 2026 at 5:18 pm

    -textField:shouldChangeCharactersInRange:replacementString: is a delegate method that let’s you allow only certain characters to be in the text field.

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { 
        NSCharacterSet *nonNumberSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
        return ([string stringByTrimmingCharactersInSet:nonNumberSet].length > 0);
    }
    

    This returns YES and therefore allows only characters that are not in the decimalDigitCharacterSet character set.

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

Sidebar

Related Questions

I am new to objective-c. I have the following: @interface HPSEnumerations : NSObject typedef
Im new to objective-c Lets assume I have a string such as this NSString*
New to objective-C, #import <objc/objc.h> #import <Foundation/Foundation.h> @interface Test:NSObject { int x,y, abc; NSString
I'm new in objective-C and i wonder if its correct: I have a class
I have a brand new Objective-C class called test . The test class has
New to objective-c and I just can't find the answer to this question anywhere.
im new with objective-c. I have problem with memory leaking when developing iphone app.
(New to Objective-C, but well versed in C/C++). Presently I have an Objective-C class
I am still new to objective-c and am trying to figure out what this
New to Objective-C and iOS development, would love a hand here! I have written

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.