• 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 problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSearchField problem


  • Subject: Re: NSSearchField problem
  • From: Jerry Krinock <email@hidden>
  • Date: Sat, 12 Oct 2013 20:30:47 -0700

Hello, Michael.

Below is a snipped of code which I use to populate the "Recent Searches" section of a similar NSSearchField.  It works.  I modified Apple's example quite a bit.

As you can see, in my code, the menu item that is tagged with NSSearchFieldRecentsMenuItemTag has nil action and no target.  That tag makes it a "magic" item which tells Cocoa to put the recent items there.  So I think the answer to your question of why the selector of that item never gets invoked is that this behavior is expected.  There are actually five (5) such magic items with magic tags, which I've commented with  // (*).

If I remember correctly, the way the "search" happens for a recent search is the same as the way the search happens for a typed-in-with-keyboard search, which is that the search field sends its action.  I also had to subclass NSSearchField to get everything working.  But maybe this will get you started.


// *** Recent Searches Section

// Separator
[searchMenu insertItem:[NSMenuItem separatorItem]
               atIndex:index++];

// "Recent Searches" Title Item
title = [[BkmxBasis sharedBasis] labelRecentSearches] ;
item = [[NSMenuItem alloc] initWithTitle:title
                                  action:nil
                           keyEquivalent:@""];
[item setTag:NSSearchFieldRecentsTitleMenuItemTag]; // (*)
[searchMenu insertItem:item
               atIndex:index++];
[item release];

// "No Recent Searches"
title = [[BkmxBasis sharedBasis] labelNoRecentSearches] ;
item = [[NSMenuItem alloc] initWithTitle:title
                                  action:nil
                           keyEquivalent:@""];
[item setTag:NSSearchFieldNoRecentsMenuItemTag]; // (*)
[searchMenu insertItem:item
               atIndex:index++];
[item release];

// Placeholder for the actual Recent Searches
item = [[NSMenuItem alloc] initWithTitle:title
                                  action:nil
                           keyEquivalent:@""];
[item setTag:NSSearchFieldRecentsMenuItemTag]; //  (*)
[searchMenu insertItem:item
               atIndex:index++];
[item release];

// Separator
item = (NSMenuItem*)[NSMenuItem separatorItem];
[item setTag:NSSearchFieldRecentsTitleMenuItemTag]; //  (*)
[searchMenu insertItem:item
               atIndex:index++];

// Clear Recent Searches
title = [[BkmxBasis sharedBasis] labelClearRecentSearches] ;
item = [[NSMenuItem alloc] initWithTitle:title
                                  action:nil
                           keyEquivalent:@""];
[item setTag:NSSearchFieldClearRecentsMenuItemTag]; //  (*)
[searchMenu insertItem:item
               atIndex:index++];
[item release];




_______________________________________________

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


  • Follow-Ups:
    • Re: NSSearchField problem
      • From: Michael de Haan <email@hidden>
References: 
 >NSSearchField problem (From: Michael de Haan <email@hidden>)

  • Prev by Date: NSSearchField problem
  • Next by Date: Skype API
  • Previous by thread: NSSearchField problem
  • Next by thread: Re: NSSearchField problem
  • Index(es):
    • Date
    • Thread