0

I'm working on an Mac App that uses popover windows for additional functionality. I have a popover that opens where I need the user to input some text and I can't seem to get the field to be editable. Under the Attributes inspector in Xcode the behavior is set to be editable and the other options match settings from a similar application that has a text field in a new window that is editable. What am I missing?

- (IBAction)dataTransferButton:(id)sender {

[[self dataTransferPopover] showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMaxXEdge];

_employeeCheckBox.enabled=NO;

[dataTransferPopover becomeFirstResponder];
userAccountTextField.editable=YES;
}
dzimmerl
  • 35
  • 1
  • 5
  • probably because the popover's window can't become keywindow or popover doesn't accept first responder. Have you checked them? – lead_the_zeppelin Apr 21 '14 at 15:19
  • possible duplicate of [NSTextField on NSPopover](http://stackoverflow.com/questions/7214273/nstextfield-on-nspopover) – lead_the_zeppelin Apr 21 '14 at 15:21
  • No duplicate NSTextField on NSPopover. I checked first responder and that didn't seem to work. [dataTransferPopover becomeFirstResponder]; – dzimmerl Apr 21 '14 at 15:39
  • In addition, I have some buttons and labs in the popover that are working. One button opens an NSPanel for the user to select a file path. After the user makes a selection the file path is reported in a label replacing some placeholder text. – dzimmerl Apr 21 '14 at 15:50
  • this almost certainly has to do with popover's parent not becoming key. Did you check that? – lead_the_zeppelin Apr 21 '14 at 15:59
  • How would I check that? – dzimmerl Apr 21 '14 at 17:24
  • update question with code. When you create the popover. – lead_the_zeppelin Apr 21 '14 at 17:32
  • Never invoke `becomeFirstResponder` directly; this isn't iOS. (See https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSResponder_Class/Reference/Reference.html#jumpTo_6) You should call `NSWindow`'s `makeFirstResponder:` like lead_the_zeppelin outlines in his/her answer. – NSGod Apr 21 '14 at 18:15
  • This is what worked for me: http://stackoverflow.com/questions/7214273/nstextfield-on-nspopover – dzimmerl May 01 '14 at 19:23

1 Answers1

0

Make your app delegate implement NSPopoverDelegate and implement

-(void)popoverDidShow:(NSNotification *)notification
{
    [self.dataTransferPopover.viewController.view.window makeKeyWindow];
    self.dataTransferPopover.viewController.view.window makeFirstResponder:userAccountTextField];
}

You need to make the textfield as first responder not the popover.

lead_the_zeppelin
  • 2,017
  • 13
  • 23
  • Ok. So I have the Master App Delegate, a Custom View, an NSPopover and a Popover View Controller. I'm not sure what's supposed to be attached where. – dzimmerl Apr 21 '14 at 19:43
  • in this case your app delegate will implement NSPopoverDelegate. I updated answer. – lead_the_zeppelin Apr 21 '14 at 22:18
  • That didn't work for me. Other ideas on what the problem could be? – dzimmerl Apr 22 '14 at 19:38
  • I tried creating a new window and putting the NSTextfield in the window and still had the same problem (this is what I'm doing in my original App where things worked). In addition, I tried moving it to my main window and I still have the same problem. Is there something broken with NSTextField? – dzimmerl Apr 24 '14 at 21:00