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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:51:52+00:00 2026-06-08T07:51:52+00:00

I just followed a tut on making a conversion app. It was good, but

  • 0

I just followed a tut on making a conversion app. It was good, but I wanted to expand on it. The tut has you input a value in for Fahrenheit and then converts to Celsius. Pretty basic. So I wanted to add a Kelvin conversion as well. But the code only let you plug in a number for the Fahrenheit. So after adding the Kelvin text field, I wanted to check to see which text box had text in it. So I used the following code:

- (IBAction)convert:(id)sender 
{
if ([fahrenheit isFirstResponder]) 
{
    float x = [[fahrenheit text] floatValue];
    float y = (x - 32.0f) * (5.0f/9.0f);  //celcius
    float z = y + 273.15f;  //kelvin
    [celcius setText:[NSString stringWithFormat:@"%3.2f" , y]];
    [kelvin setText:[NSString stringWithFormat:@"%3.2f" , z]];
    [fahrenheit resignFirstResponder];
} else if ([celcius isFirstResponder])
{
    float x = [[celcius text] floatValue];
    float y = 32.0f + ((9.0f/5.0f) * x); //farenheit
    float z = x + 273.12f; //kelvin
    [fahrenheit setText:[NSString stringWithFormat:@"%3.2f" , y]];
    [kelvin setText:[NSString stringWithFormat:@"%3.2f" , z]];
    [celcius resignFirstResponder];
}else if ([kelvin isFirstResponder])
{
    float x = [[kelvin text] floatValue];
    float y = x - 273.15f; //celcius
    float z = 32.0f + ((9.0f/5.0f) * y); //farenheit
    [celcius setText:[NSString stringWithFormat:@"%3.2f" , y]];
    [fahrenheit setText:[NSString stringWithFormat:@"%3.2f" , z]];
    [kelvin resignFirstResponder];
}
}

This allowed me to input a number in any text field and then convert. But then I decided to dismiss the keyboard. My code said to resignFirstResponder. But then the convert action did not work because now there was no first responder. Any clues as to how I can check which text box has text in it, and then do the conversions? Thanks in advance for any help.

  • 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-08T07:51:54+00:00Added an answer on June 8, 2026 at 7:51 am
    if( [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] != nil &&  [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] != @"" )
    {
        // text field has text
        
        // get text without white space
        
        NSString * textWithoutWhiteSpace = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've followed this example: RCP+JavaWS but the app just briefly comes up and goes
I just deployed my first django app to the Heroku platform. I basically followed
I followed this instruction but not worked for me. I just wanna install and
I just followed railscast 134 to install paperclip into my rails 3.0.1 app. I
I am using fb_graph for my rails app. I just followed nov/fb_graph app. It
i'm making a lightbox, i've followed tutorials just to get this far, and i'm
I just followed the exact code in API Demo, but my service just won't
I am new to Google App Engine and so, I just followed the procedure
I followed the demo and things are working just fine. My client has a
I realized today that I have blindly just followed this requirement for years without

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.