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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:35:03+00:00 2026-05-16T00:35:03+00:00

I have a method that gets called any time a control on my view

  • 0

I have a method that gets called any time a control on my view changes and should update a UILabel. It has two UITextFields and two UISliders. First I check to see if either of the UITextFields are empty and if so, advise that they need to be filled in. Otherwise I get the difference between the UITextFields’ values and generate a couple of floats to use in my NSStrings.

I get a warning that message is not used and I get an error about the NSStrings (can’t remember now exactly what – I’m not at my Mac…)

And even when I chopped the messages down to something simple that worked, when delta == 0, it does the delta <= 0 message.

Oh, and the strings don’t put the values in where the % signs are, they just print the % signs.

I’ve been hacking at this too long and need help…

- (void)updateAdvice {
    if ([chlorineSourceField.text isEqualToString:@""] || [poolVolumeField.text isEqualToString:@""]) {
        NSString *message =  [[NSString alloc] initWithString:@"Enter a chlorine source and pool volume."];
    }
    else {
        int delta = [targetLabel.text intValue] - [startingLabel.text intValue];
        float chlorineAmount = delta * [poolVolumeField.text intValue] * chlorineConstant;
        float percentRemove = (1 - ([targetLabel.text floatValue] / [startingLabel.text floatValue]));
        float gallonsRemove = percentRemove * [poolVolumeField.text intValue];
        if (delta == 0) {
            NSString *message = [[NSString alloc] initWithString:@"No adjustments necessary.  You're on target"];
        }
        if (delta >= 0) {
            NSString *message = [[NSString alloc] initWithFormat:@"To increase FC by %dppm, add %3.1f oz of %@.", delta, chlorineAmount, chlorineSourceField.text];
        }
        if (delta <= 0) {
            NSString *message = [[NSString alloc] initWithFormat:@"You're above target already.  Replace %d%% or %d gallons of water - or just wait for it to come down.", percentRemove*100, gallonsRemove];
        }
    }
    adviceLabel.text = message;
    [message release];
}
  • 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-05-16T00:35:03+00:00Added an answer on May 16, 2026 at 12:35 am

    You are missing the else part, thus all three if statements are being evaluated consecutively. If delta == 0, it will satisfy all three if statements. Thus, the last allocation will overwrite the previous two. (And you’ll be leaking memory)

    Also, your message variable is scoped as local to the if block it’s declared into. You might want to move the message declaration at the function level scope.

    As far as % not working, you are using the instance initializer initWithFormat with the syntax for the class initializer stringWithFormat. initWithFormat takes the parameters for the formatted string in a separate parameter – arguments:. (Btw, it also requires locale:)

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

Sidebar

Related Questions

If CodeIgniter has _remap() that gets called before it touches any method in a
I have this method that gets called when i press a button and removes
I have an action method VerifyNewUser() that gets called when the user clicks a
I have a method, -(void)validateFormInput:(UITextField *)textField that gets called when the form's submit button
Hey guys. I have a method that gets called each second which I want
I have a method that gets a string and change that to a particular
I have a AJAX post method that gets xml data from server. But when
I have a very basic doubt regarding the method that gets executed when app
I want to make a hook method which gets called everytime any function of
I have method that returns Drawable , and if its Bitmap object is recycled

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.