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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:05:43+00:00 2026-05-27T13:05:43+00:00

I can’t figure out how to get an NSTextfield to update automatically, without having

  • 0

I can’t figure out how to get an NSTextfield to update automatically, without having to press “Return” or click another text field.

My goal is to input a number into a field and have the other fields update simultaneously. I tried clicking “Continuous” in the text field attributes but it doesn’t seem to do anything.

Here is my interface file:

#import <Foundation/Foundation.h>

@interface InchController : NSObject {
    IBOutlet NSTextField *centimetersTextField;
    IBOutlet NSTextField *inchesTextField;
    IBOutlet NSTextField *feetTextField;
}

-(IBAction)convert:(id)sender;

@end

Here is my implementation file:

#import "InchController.h"

@implementation InchController

- (IBAction)convert:(id)sender {

    if (sender == inchesTextField) {
        float inches = [inchesTextField floatValue];
        [feetTextField setFloatValue:(inches * 0.0833)];
        [centimetersTextField setFloatValue:(inches * 2.54)];
    }
    else if (sender == feetTextField) {
        float feet = [feetTextField floatValue];
        [inchesTextField setFloatValue:(feet * 12)];
        [centimetersTextField setFloatValue:(feet * 30.48)];
    }
    else if (sender == centimetersTextField) {
        float centimeters = [centimetersTextField floatValue];
        [inchesTextField setFloatValue:(centimeters * 0.394)];
        [feetTextField setFloatValue:(centimeters * 0.033)];
    }

}

@end

So here is the updated implementation file per Josh’s solution. Commented out the IBAction since it is no longer needed in the implementation and interface files.

#import "LengthController.h"

@implementation LengthController

//- (IBAction) convert: (id)sender {
//}

-(void) controlTextDidChange:(NSNotification *) note {

    NSTextField *changedField = [note object];

    if (changedField == inchesTextField) {
        float inches = [inchesTextField floatValue];
        [feetTextField setFloatValue: (inches * 0.0833)];
        [centimetersTextField setFloatValue: (inches * 2.54)];
    }

    if (changedField == centimetersTextField) {
        float centimeters = [centimetersTextField floatValue];
        [inchesTextField setFloatValue:(centimeters * 0.394)];
        [feetTextField setFloatValue:(centimeters * 0.033)];
    }

    if (changedField == feetTextField) {
        float feet = [feetTextField floatValue];
        [inchesTextField setFloatValue:(feet * 12)];
        [centimetersTextField setFloatValue:(feet * 30.48)];
    }
}

@end
  • 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-27T13:05:43+00:00Added an answer on May 27, 2026 at 1:05 pm

    Make your controller the delegate of the text fields; you can set this in Interface Builder by Ctrl-dragging from the text fields to the controller.

    In your controller, implement the “NSControl Delegate” method controlTextDidChange:, which will be called (as its name suggests) whenever the field’s text changes. In that method, you can validate the text and, if appropriate, update the contents of the other fields.

    The argument that is passed in can give you the text field which changed; you can then pass that on to your existing convert: method to reuse the code:

    - (void) controlTextDidChange: (NSNotification *)note {
    
        NSTextField * changedField = [note object];
        [self convert:changedField];
    }
    

    There’s nothing special about action methods. The IBAction return type evaluates to void; it’s only used by Xcode to expose the method for use in Interface Builder. You can, therefore, call them just like any other method. Here, you get the appropriate field and pass it in as the sender parameter, as if the field had called the action method itself.

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

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can somebody point me to a resource that explains how to go about having
Can I get a 'when to use' for these and others? <% %> <%#
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can anyone give me an example of how to return the following json simply
Can PHP PDO extension bind nested objects automatically ? I mean using foreign key
Can you guys help me understand a concept real quick, I'm having trouble understanding
Can i get the source code for a WAMP stack installer somewhere? Any help
Can't work out a way to make an array of buttons in android. This
Can somebody point me a good strategy for security crosscutting concern without AOP for

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.