Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa: auto completing a string in a text field

Cocoa: auto completing a string in a text field
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Nov 22, 2002, 02:51 AM
 
I was wondering how I can make it so that an NSTextField will autocomplete a string as the user begins typing in it? I would really like the behavior of the TO: textfield in Mail.app which has a menu drop down filled with options of strings the user can select. I have found NSComboBox, but that isn't what I want. Any suggestions?

The strings which should match up to the one the user is typing will be stored in an NSArray.

TIA
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Nov 22, 2002, 04:13 PM
 
Implement -controlTextDidChange: in your TextField's delegate. There you can do whatever array comparisons, etc. you need to find matches. Apple isn't really doing any custom-control magic to make a list of matches show up -- they just put up a borderless window containing a TableView, and you can do the same.

Oh, and if you need some help with the string-matching logic, see OATypeAheadSelectionHelper in the open-source OmniAppKit framework.
Rick Roe
icons.cx | weblog
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Nov 23, 2002, 04:51 PM
 
Nice tip Rickster - I always wondered how they did that.



plus I learned a lot about windows by doing that.

I found that sending orderOut: to a window attached to another window hides both - is that supposed to happen?
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Jan 14, 2003, 04:09 PM
 
Ok, I have one last question on this issue, I now have it so that a little window appears along a table row, but when it does so, the scrollbar on the parent window becomes greyed out. How do you have it so that the child window, which in my case they type into because it has an NSTextView in it, is the "key" window, while the other parent window remains "key" also. Do you know what I am saying? (I don't know if use of "key" is correct or not.)

I want to do what Apple did with Address Book where they have little windows "appear" as you are editing, but the main window doesn't grey out or anything.

Anyone know how to do this?
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Jan 14, 2003, 11:04 PM
 
Make the window a borderless utility panel rather than a normal window?

I'm just guessing here, but I don't think it could hurt to try...
[Wevah setPostCount:[Wevah postCount] + 1];
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Jan 14, 2003, 11:30 PM
 
Good thinking, but I just tried it and still no luck.

Surely someone knows how to do it? Rickster?
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Jan 15, 2003, 02:54 AM
 
The things in Address book aren't windows. They're just a custom border around a text field.
Rick Roe
icons.cx | weblog
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Jan 15, 2003, 10:27 AM
 
Ok. But in Mail they have the borderless window appear below the To: field without the scrollbar on the message window turning grey. Do you know how they do that?
     
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status: Offline
Reply With Quote
Jan 16, 2003, 02:50 AM
 
Originally posted by Rickster:
The things in Address book aren't windows. They're just a custom border around a text field.
How would you do that then?
Luke
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Jan 16, 2003, 05:21 AM
 
Another wild guess...maybe a borderless panel, with becomesKeyOnlyIfNeeded set to YES?

*shrug*

I'd like to know, too...
[Wevah setPostCount:[Wevah postCount] + 1];
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Jan 16, 2003, 05:41 PM
 
Originally posted by Wevah:
Another wild guess...maybe a borderless panel, with becomesKeyOnlyIfNeeded set to YES?
Still no luck...darn.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jan 16, 2003, 06:37 PM
 
Would just putting up an NSView not work?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Jan 16, 2003, 07:28 PM
 
I don't know. Can I still get the drop shadow and make it so that the view is "attached" to the "parent window"?
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Jan 17, 2003, 12:30 AM
 
Hmmm...I keep hearing about layered views doing odd things...
[Wevah setPostCount:[Wevah postCount] + 1];
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:23 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2