Note that there are some explanatory texts on larger screens.

plurals
  1. PONSTextField continuous update
    primarykey
    data
    text
    <p>I can't figure out how to get an <code>NSTextfield</code> to update automatically, without having to press "Return" or click another text field.</p> <p>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.</p> <p>Here is my interface file:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface InchController : NSObject { IBOutlet NSTextField *centimetersTextField; IBOutlet NSTextField *inchesTextField; IBOutlet NSTextField *feetTextField; } -(IBAction)convert:(id)sender; @end </code></pre> <p>Here is my implementation file:</p> <pre><code>#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 </code></pre> <p>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.</p> <pre><code>#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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload