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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:06:50+00:00 2026-06-15T18:06:50+00:00

it is probably a very simple problem but I spent already a lot of

  • 0

it is probably a very simple problem but I spent already a lot of time on it and just have given up…
I have a button and a textfield for speed calculations. I want the button label change once the button is pressed (km/h >> mph >> m/s >> km/h and so on) and speed recalculated. It sometimes works fine but very often it jumps to “else” statement even if the CurrentSpeedValue is @”km/h”. Could anyone help? Maybe it would be better to use switch-case method but how should it be stated?

- (IBAction)speedChange:(id)sender {
//CurrentSpeedUnit is saved to NSUserDefault in another action
    if (CurrentSpeedUnit == @"km/h") {
        [sender setTitle:@"mph" forState:UIControlStateNormal];
        CurrentSpeedUnit = @"mph";
        float speedToPrint = ([textSpeed.text floatValue]) / 1.609344;
        textSpeed.text = [[NSString alloc] initWithFormat:@"%.3f", speedToPrint];
    } else if (CurrentSpeedUnit == @"mph") {
        [sender setTitle:@"m/s" forState:UIControlStateNormal];
        CurrentSpeedUnit = @"m/s";
        float speedToPrint = ([textSpeed.text floatValue]) * 1.609344 / 3.6;
        textSpeed.text = [[NSString alloc] initWithFormat:@"%.3f", speedToPrint];
    } else {
        [sender setTitle:@"km/h" forState:UIControlStateNormal];
        CurrentSpeedUnit = @"km/h";
        float speedToPrint = ([textSpeed.text floatValue]) * 3.6;
        textSpeed.text = [[NSString alloc] initWithFormat:@"%.3f", speedToPrint];
    }
}
  • 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-15T18:06:51+00:00Added an answer on June 15, 2026 at 6:06 pm

    You should not compare strings like that (you compare pointers but not the contents). Use isEqualToString.

    i.e.

    if ([CurrentSpeedUnit isEqualToString:@"km/h"]) {
    ...
    

    but not your

    if (CurrentSpeedUnit == @"km/h") {
    

    It may work sometimes, but just remember to avoid comparing strings with ==

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

Sidebar

Related Questions

Very simple problem, but can't seem to solve it. I'm probably just not thinking
Probably a very simple problem and I have been looking for the answer but
I have a strange problem which probably has a very simple solution, I just
I'm a newbie with WPF and c# and have a (probably very simple) problem.
XML problem that's got me stumped, but is probably very simple... The XML is
This is probably a very simple problem but forgive me as I am new.
This problem is probably very simple to solve but it is not clear to
This is probably a very simple and stupid question to ask, but I have
I'm aware this is probably a very simple problem with a 1-line-of-code answer but
I have probably a simple math problem that I'm having surprisingly hard time figuring

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.