Jump to content
Welcome to InsanelyMac Forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  

UIKeyboardTypeDecimalPad Help

1 post in this topic

Recommended Posts

Hey, I feel like a noob asking this question, in fact I am a noob as far as Objective-c goes. How can I use UIKeyboardTypeDecimalPad with my iOS application? As in the exact code where to put it. Do I need to create a new file?


Here's my existing code:




#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController {
   IBOutlet UITextField *labelF;
   IBOutlet UITextField *labelC;
   IBOutlet UITextField *labelK;
- (IBAction) enterF;
- (IBAction) enterC;
- (IBAction) enterK;




#import "SecondViewController.h"

@implementation SecondViewController

- (IBAction)enterF {
   //C = ( F - 32) / 1.8
   float c = ([labelF.text floatValue])-32/1.8;
   //K = ( F + 459.67) / 1.8
   float k = (([labelF.text floatValue])+459.67)/1.8;

   //Enter the conversions into labelC and labelK.
   labelC.text = [[NSString alloc] initWithFormat:@"%f", c];
   labelK.text = [[NSString alloc] initWithFormat:@"%f", k];
   labelF.keyboardType = UIKeyboardTypeDecimalPad;

- (IBAction)enterC {
   //F = C × 1.8 + 32
   float f = ([labelC.text floatValue])*1.8+32;
   //K = C + 273.15
   float k = ([labelC.text floatValue])+273.15;

   //Enter the conversions into labelF and labelK.
   labelF.text = [[NSString alloc] initWithFormat:@"%f", f];
   labelK.text = [[NSString alloc] initWithFormat:@"%f", k];
   labelC.keyboardType = UIKeyboardTypeDecimalPad;

- (IBAction)enterK {
   //F = K × 1.8 - 459.67
   float f = ([labelK.text floatValue])*1.8-459.67;
   //C = K - 273.15
   float c = ([labelK.text floatValue])-273.15;

   //Enter the conversions into labelF and labelC.
   labelF.text = [[NSString alloc] initWithFormat:@"%f", f];
   labelC.text = [[NSString alloc] initWithFormat:@"%f", c];
   labelK.keyboardType = UIKeyboardTypeDecimalPad;

- (void)dealloc
   [super dealloc];

- (void)didReceiveMemoryWarning
   // Releases the view if it doesn't have a superview.
   [super didReceiveMemoryWarning];

   // Release any cached data, images, etc that aren't in use.

#pragma mark - View lifecycle

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
[super viewDidLoad];

- (void)viewDidUnload
   [super viewDidUnload];
   // Release any retained subviews of the main view.
   // e.g. self.myOutlet = nil;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
   // Return YES for supported orientations
   return (interfaceOrientation == UIInterfaceOrientationPortrait);



I have the actions and outlets connected to three text fields in the nib file.


As you can probably see, I'm trying to make a temperature converter.

People need to put in decimal places, hence the need of UIKeyboardTypeDecimalPad.


I'm a noob, and asking on Q/A sites is getting me nowhere. If you could just add it to the code or show me what the file would look like, I'll be able to figure out why.Like literally copy the code and put in the code. And then tell me if I need to make new files or connect anything in IB.

I just need those three text boxes, already made in IB, to have the Decimal Pads pop up when you touch into the text boxes.

Thanks. I would also appreciate code to dismiss the decimal pad and to make it so that if someone doesn't have 4.1 so that it will revert to a compatible keyboard, but that's not necessary. All I need is the code for the UIKeyboardTypeDecimalPad.


Thank you so much to anyone who considers answering! I've spent hours trying to figure this out and it would be great if anyone can solve. And please don't provide me a link to an explanation, only to solid code that I can see where it it.

Thank you if you even consider answering the question and saving me a few hours!



Problem solved, I feel even more stupid now. Just needed to add

- (void)viewDidLoad


[super viewDidLoad];



Lame. Well, I actually figured out something for myself for once!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.