• 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: selectText of NSTextField on focus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: selectText of NSTextField on focus


  • Subject: Re: selectText of NSTextField on focus
  • From: Mike Abdullah <email@hidden>
  • Date: Mon, 06 Jul 2015 21:03:21 +0100

> On 6 Jul 2015, at 20:38, Richard Charles <email@hidden> wrote:
>
>> On Jul 6, 2015, at 12:12 PM, Gary L. Wade wrote:
>>
>> You want to select the text using the associated text view of the NSTextField control.
>
> Not sure what you mean by the "associated text view" of the control. Do you mean the field editor of the control? I have subclassed NSTextField and overridden becomeFirstResponder. NSTextField is a subclass of NSControl which is a subclass of NSView.
>
>
>> On Jul 6, 2015, at 12:07 PM, Quincey Morris wrote:
>>
>> On Jul 6, 2015, at 10:54 , Richard Charles wrote:
>>
>>>      [self performSelector:@selector(selectText:) withObject:self afterDelay:0];
>>
>> I dunno, but I suspect that this isn’t good enough. You’re merely guessing that “on the next iteration of the run loop” is *after* the text field finished becoming first responder, but it may take time to get the text field into a state where its selection can be set.
>
> Yes I think that is the case. The following code works.
>
> [self performSelector:@selector(selectText:) withObject:self afterDelay:0.1];
>
>
>> I’d suggest you try selecting the text in a delegate method (textDidBeginEditing or controlTextDidBeginEditing) instead.
>
> The delegate methods textDidBeginEditing: and controlTextDidBeginEditing: are not called when clicking into the view. They are called when the first edit is actually attempted. So that did not work.
>
>
> In fiddling around with afterDelay: values this is what I found.
>
>     afterDelay:0.01 // This did not work. Text not selected.
>
>     afterDelay:0.02 // This works. Text is selected.
>
>     afterDelay:0.1 // This works. Text is selected.
>
>     afterDelay:1.0 // This works but the delay is too long.
>
> So do you think I am safe using this call.
>
> [self performSelector:@selector(selectText:) withObject:self afterDelay:0.1];

No.

Almost any time you have a delayed perform in your code, you’re doing something a bit dubious, and you’ve just wandered into proper dodgy territory, where your code is guaranteed to be unreliable.


_______________________________________________

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: 
 >selectText of NSTextField on focus (From: Richard Charles <email@hidden>)
 >Re: selectText of NSTextField on focus (From: Richard Charles <email@hidden>)
 >Re: selectText of NSTextField on focus (From: Quincey Morris <email@hidden>)
 >Re: selectText of NSTextField on focus (From: Richard Charles <email@hidden>)

  • Prev by Date: Re: selectText of NSTextField on focus
  • Next by Date: Swift Enums and CoreData
  • Previous by thread: Re: selectText of NSTextField on focus
  • Next by thread: Re: selectText of NSTextField on focus
  • Index(es):
    • Date
    • Thread