Skip navigation.
 
ml-stringValue on NSTextfield does not reflect actual contents
FROM : Philip Dow
DATE : Sat Jul 22 22:31:07 2006

I am building a window in code. It contains a text field and two 
buttons, one "OK" the other "Cancel." The window does not use any 
bindings and I am running it modally.

The window comes to the fore when the user drags an item onto the 
relevant object. The dragged item contains a string which is 
initially displayed in the text field. The user can edit that string 
value.

If the user presses return when finished editing, calling -
stringValue on the text field returns the correct value. However, if 
the user clicks the "OK" button, calling -stringValue returns the 
field's initial value rather than the edited version. I'm stumped as 
to why it does this.

The code that builds the text field follows:

   NSTextField *title = [[NSTextField alloc] initWithFrame:NSMakeRect
(20,60,219,22)];
   [title setStringValue:defaultTitle];
   [title setSelectable:YES];
   [title setEditable:YES];
   [title setBezeled:YES];
   [title setDrawsBackground:YES];
   [title setBezelStyle:NSTextFieldSquareBezel];
   [title setAutoresizingMask:NSViewWidthSizable];
   [[title cell] setScrollable:YES];
   [[title cell] setControlSize:NSRegularControlSize];
   [title setFont:[NSFont systemFontOfSize:[NSFont 
systemFontSizeForControlSize:NSRegularControlSize]]];

The "OK" button is made to respond to a Return key with [sheetWin 
setDefaultButtonCell:[okay cell]];

I grab the text field's string with returnValue = [title stringValue];

Setting an action and target on the text field or setting the 
sendsActionOnEndEditing value makes no difference. I'm sure I just 
need to add one line of code somewhere, but I don't know what it is.

-Phil

Related mailsAuthorDate
ml-stringValue on NSTextfield does not reflect actual contents Philip Dow Jul 22, 22:31
mlRe: -stringValue on NSTextfield does not reflect actual contents Keary Suska Jul 23, 02:26
mlRe: -stringValue on NSTextfield does not reflect actual contents [SOLVED] Philip Dow Jul 23, 10:19