Hi Kyle, thanks for the reply.

On 1 August 2011 01:12, Kyle Sluder <kyle.slu...@gmail.com> wrote:

> On Sun, Jul 31, 2011 at 4:29 PM, Joe White <j...@rjdj.me> wrote:
> > Hi all,
> >
> > I'm currently implementing custom autocomplete functionality into a
> > NSTextField. I've managed so far to generate a list of my own available
> > words and these show when escape is pressed.
> >
> > However, I'd like the autocompletion to automatically show as the user
> > types.
>
>
> Have you thought about how this will interact with the default
> autocorrect-options-as-you-type on Lion?
>
> Actually, I haven't even looked at Lion yet. I don't want to update halfway
through a project (not code based). Can you explain more or is there a link
I can read? Sounds like this could be trouble.

>
> >
> > I'm using the delegate methods of a NSTextView to override -
> > (NSArray*)textView:(
> > NSTextView *)textView completions:(NSArray *)words
> >  forPartialWordRange:(NSRange)charRange
> indexOfSelectedItem:(NSInteger*)index
> >
> > And setting the delegate in - (void)controlTextDidBeginEditing:(
> > NSNotification *)obj {
> >
> >  fieldEditor = [[obj userInfo] objectForKey:@"NSFieldEditor"];
> >
> >  [fieldEditor setDelegate:self]; }
>
> Do not change the delegate of a field editor. It needs to be the
> control that's being edited. This is the mechanism whereby
> -controlTextDidChange: gets called.
>
> You have two options:
>
> 1. Subclass NSTextField, override the appropriate text view delegate
> methods (like -textDidChange: or
> -textView:shouldChangeTextInRange:replacementString:), and call
> super's implementation.
>
> 2. Add your object as an observer of the relevant NSNotifications on
> the field editor. You might still need to subclass NSTextField so you
> can perform your setup in -setUpFieldEditorAttributes:, but most
> likely you could get away with doing this in your window delegate's
> -window:willReturnFieldEditor:toObject:. Still, this approach is
> slightly less powerful, but if you don't need all the power of being
> the field editor's delegate it could result in a cleaner
> implementation.
>
> After some more exploring I found that I could receive the NSTextView
delegate methods with -textDidChange instead of -controlTextDidChange. This
seems to work but I get the impression this is not the correct approach.

I'd prefer option 2 if it is the cleaner way, as long as I still have
control over the text input. I'm aiming at a similar approach to Xcode,
where it displays the available methods and shows the parameters needed.

p.s. I was just talking to a colleague and he said he turned Lion's default
autocomplete off straight away as it was annoying :S

Thanks,
Joe

>  --Kyle Sluder
>



-- 
Joe White
Production Department, RjDj

Tel : +44 7515 731499

Reality Jockey Ltd.
Floor B “The Mission”
55 Holywell Lane
London
EC2A 3PQ
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to