Re: NSTextField with a NSTableView completion list - suggestions for text field
Re: NSTextField with a NSTableView completion list - suggestions for text field
- Subject: Re: NSTextField with a NSTableView completion list - suggestions for text field
- From: Ken Thomases <email@hidden>
- Date: Fri, 20 Mar 2015 02:13:13 -0500
On Mar 19, 2015, at 6:20 PM, Alex Kac <email@hidden> wrote:
> I have a few places where I’d like to have essentially an NSTextField with an auto-complete - but its not a combo-box. The closest I can come up with what I’m looking for is the Apple Calendar location field where it brings up a search auto-complete. A few things are that it looks like a standard text field and you can type any text you want, but you can also select something from the completion list. The completion list is also an attributed string or a table cell that lets us customize the look just like it:
>
> https://www.dropbox.com/s/w61ztjlwzv414l6/Screenshot 2015-03-19 15.47.05.png?dl=0
>
> So what are my best options here?
Without customized appearance, I would recommend that you make a custom subclass of NSTextField that implements -textDidChange: to call -complete: on the field editor (which would be the "object" of the NSNotification object that you receive). It would also implement -textView:completions:forPartialWordRange:indexOfSelectedItem: to provide the completions.
For a more custom look, check out Apple's CustomMenus sample project <https://developer.apple.com/library/mac/samplecode/CustomMenus/Introduction/Intro.html>. There's also an associated WWDC video (with a confusingly-unrelated title) <https://developer.apple.com/videos/wwdc/2010/?id=145>. It illustrates exactly a suggestion menu for a text field.
Regards,
Ken
_______________________________________________
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