• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Selected text in NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Selected text in NSTextField


  • Subject: Re: Selected text in NSTextField
  • From: Dave Fernandes <email@hidden>
  • Date: Thu, 02 Feb 2012 20:50:17 -0500

On 2012-02-02, at 8:11 PM, Graham Cox wrote:

>
> On 03/02/2012, at 11:39 AM, Dave Fernandes wrote:
>
>> Am I trying the right things here?
>
>
> It should just work if you set the 'initialFirstResponder' outlet to be your text field. No other code needed, except possibly NOT calling -setBecomesKeyOnlyIfNeeded:YES.
>
> The docs suggest this is only called the first time the window is shown - for sheets and other dialogs, often they are only hidden rather than discarded when closed, so it might not work for subsequent showing of the dialog, but simply making the view returned by -initialFirstResponder the first responder should work, i.e.
>
> [myPanel makeFirstResponder:[myPanel initialFirstResponder]];

This was the first thing I tried, but it didn't even work in Snow Leopard when the text field was inside an NSTabView. So then I tried performSelector after reading an old post on this topic. And that works on Snow Leopard, but not always on Lion.

I also tried setting the initialFirstResponder of the NSTabViewItem to be my text field and the initialFirstResponder of the window to be the NSTabView. It still doesn't get focus without the aforementioned kludges.

> when you display the sheet. I'm not sure if the -performSelector stuff is needed - I guess you're trying to ensure that the window is really there and the event loop is running but AFAIK, that's not necessary at least after the first time it is displayed. I usually end up calling my 'dialog set up' method from two places - one in -windowDidLoad, and the other just after -beginSheet…. The two calls are mutually exclusive in the sense that on the first run, the call after beginSheet finds all the outlets nil, so does nothing, and -windowDidLoad is only called the first time. While not super elegant I've never encountered any unreliability with it.
>
> --Graham
>
>


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Re: Selected text in NSTextField (From: Graham Cox <email@hidden>)
 >Re: Selected text in NSTextField (From: Quincey Morris <email@hidden>)
 >Re: Selected text in NSTextField (From: Graham Cox <email@hidden>)
 >Re: Selected text in NSTextField (From: Dave Fernandes <email@hidden>)
 >Re: Selected text in NSTextField (From: Graham Cox <email@hidden>)
 >Re: Selected text in NSTextField (From: Dave Fernandes <email@hidden>)
 >Re: Selected text in NSTextField (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: NSTextView
  • Next by Date: How to show last name of user in text field whose first name is selected in popup button
  • Previous by thread: Re: Selected text in NSTextField
  • Next by thread: Re: Drag & Drop/Pasteboard issue in Lion
  • Index(es):
    • Date
    • Thread