1

I have used the following code to add a NSTextField onto the NSAlert successfully:

NSAlert *alert = [NSAlert alertWithMessageText: @"Password"
                                          defaultButton:@"OK"
                                        alternateButton:@"Cancel"
                                            otherButton:nil
                              informativeTextWithFormat:@""];

         NSTextField *input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)];
         [input setStringValue:@""];
         [input autorelease];
         [alert setAccessoryView:input];

         NSInteger button = [alert runModal];

However the displayed NSTextField on NSAlert doesn't allow to type text, whatever I enter it does not show on the NSTextField. I also tried the set Enabled and Editable to YES but nothing changed.

  • Just built new project with this code in `applicationDidFinishLaunching:`, and it seems to work as expected - I was able to enter text in text field. Perhaps, your code doing something else in another part? – Borys Verebskyi Feb 27 '16 at 16:00
  • Same for me, the code is definitely working.. I use ARC, maybe it has something to do with autoreleasing? Additionally the alertWithMessageText.. method is deprecated since OS X 10.10. I don't know which OS versions you target, just a hint.. – mangerlahn Feb 27 '16 at 17:31
  • Thanks a lot. I have worked with this code on Mac OS 10.9. I will try it on 10.10. If it won't work on 10.9 I will make a NSPanel instead :) – BigStrewBurry Feb 28 '16 at 07:04

0 Answers0