• 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: Case insensitive autocomplete
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Case insensitive autocomplete


  • Subject: Re: Case insensitive autocomplete
  • From: Robert Martin <email@hidden>
  • Date: Wed, 23 Mar 2005 13:59:58 -0500

On Mar 23, 2005, at 11:05 AM, Ian was here wrote:

Does anyone know how to make an NSComboBoxCell do case
insensitive autocomplete? Like the way Interface
Builder does when typing in actions and outlets for a
class.

I found a hack on google that uses poseAsClass to get around the IB restriction. It works fine for me. I can't remember where I found it, so I'll paste it here.


(you should bear in mind the usual caveats about using poseAsClass)

All you need to do is add this class to your project, include "MYComboCell.h" in main.c, and add the following line to main.c: [[MYComboCell class] poseAsClass:[NSComboBoxCell class]];


@interface MYComboCell : NSComboBoxCell { } - (NSString *)completedString:(NSString *)substring; @end


@implementation MYComboCell

- (NSString *)completedString:(NSString *)substring
{
if ([self usesDataSource])
{
return [super completedString:substring];
}
else // basically do what complete should do -- be case insensitive.
{
NSArray *currentList = [self objectValues];
NSEnumerator *theEnum = [currentList objectEnumerator];
id eachString;
int maxLength = 0;
NSString *bestMatch = @"";

while (nil != (eachString = [theEnum nextObject]) )
{
NSString *commonPrefix = [eachString commonPrefixWithString:substring options:NSCaseInsensitiveSearch];
if ([commonPrefix length] >= [substring length] && [commonPrefix length] > maxLength)
{
maxLength = [commonPrefix length];
bestMatch = eachString;
break;


// Build match string based on what user has typed so far, to show changes in capitalization.
//bestMatch = [NSString stringWithFormat:@"%@%@",substring, [eachString substringFromIndex:[substring length]]];
}
}
return bestMatch;
}
}
@end


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Case insensitive autocomplete (From: Ian was here <email@hidden>)

  • Prev by Date: Re: Case insensitive autocomplete
  • Next by Date: Re: loop efficiency & messages
  • Previous by thread: Re: Case insensitive autocomplete
  • Next by thread: Case insensitive autocomplete
  • Index(es):
    • Date
    • Thread