• 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: NSSearchField loses focus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSearchField loses focus


  • Subject: Re: NSSearchField loses focus
  • From: Justin Anderson <email@hidden>
  • Date: Wed, 21 Jan 2004 13:23:13 -0500

Well the reason you don't get sorting with an empty searchString is because you return the array "as is" in the first 2 lines of the method. I had to deal with both of the problems you're having a couple days ago. Sorting takes place in [super arrangeObjects:filteredObjects], so you'll want to always call that at the end of your subclass. Better code would be:

- (NSArray *)arrangeObjects:(NSArray *)objects {

if (searchString == nil) {
return [super arrangeObjects:objects];
}

//snip... lala...

}

And the NSSearchField loses focus because of the way the example has you set it up in IB. They make you connect it's search action but also bind it's value to searchString in your array controller. What ends up happening is:
NSSearchField calls the -search: action after timeout.
Array controller sets searchString from NSSearchField.
Binding causes NSSearchField to update itself with the "new" value in searchString.
Updating NSSearchField's value causes you to lose focus.

So get rid of the value binding on NSSearchField and you'll keep focus. I *think* that's all I had to do. If not, I'll pull out my old project.

- Justin Anderson

On Jan 21, 2004, at 12:18 PM, Peer Allan wrote:

Using a custom NSArrayController I am searching a table below is my searching code.

- (NSArray *)arrangeObjects:(NSArray *)objects {

if (searchString == nil) {
return objects;
}

NSMutableArray *filteredObjects = [NSMutableArray arrayWithCapacity:[objects count]];
NSEnumerator *objectsEnumerator = [objects objectEnumerator];
id item;

while (item = [objectsEnumerator nextObject]) {
if ([[item valueForKeyPath:@"name"] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound) {
[filteredObjects addObject:item];
}
}

return [super arrangeObjects:filteredObjects];
}

This is almost straight out of Apple's docs.

The problem is that when I try to do a live search. The search field loses focus and interrupts my typing of the query when the Controller returns results from what I have entered up to that point (usually 2 or 3 character). Any ideas where I should look to solve this?

Peer
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSSearchField loses focus
      • From: Peer Allan <email@hidden>
References: 
 >NSSearchField loses focus (From: Peer Allan <email@hidden>)

  • Prev by Date: matching interface builder object to source
  • Next by Date: Re: Question about multi-processing, multi-threading...
  • Previous by thread: NSSearchField loses focus
  • Next by thread: Re: NSSearchField loses focus
  • Index(es):
    • Date
    • Thread