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? > > 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. --Kyle Sluder _______________________________________________ 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