Kyl*_*yle 6 macos cocoa nsmenu
我的应用程序具有默认的“帮助”菜单。我删除了“帮助”条目并添加了一个链接到我网站上的论坛的支持条目。
帮助菜单笔尖如下所示:

但是一旦我启动了应用程序并运行了一个新的菜单项,它就会被吸引进来:

我怎样才能让搜索消失?(或者更好的是,我怎样才能让它启动一个带有参数的网址,例如http://mywebsite.com/support?search=XXXXX)。
我找到了删除搜索栏的方法(但不是自定义它)。
只需分配一个不使用的菜单到帮助菜单即可:
NSMenu *unusedMenu;
unusedMenu = [[NSMenu alloc] initWithTitle:@"Unused"];
NSApplication *theApp;
theApp = [NSApplication sharedApplication];
theApp.helpMenu = unusedMenu;
Run Code Online (Sandbox Code Playgroud)
文档在 NSApplication 类的 helpMenu 属性中提到了这一点。
您正在寻找NSUserInterfaceItemSearching协议。返回单个搜索结果项并使用它来打开您的自定义 URL。
- (void)searchForItemsWithSearchString:(NSString *)searchString resultLimit:(NSInteger)resultLimit matchedItemHandler:(void (^)(NSArray *items))handleMatchedItems
{
handleMatchedItems(@[searchString]);
}
- (NSArray *)localizedTitlesForItem:(id)item
{
return @[[NSString stringWithFormat:@"Search for '%@' on my website", [item description]]];
}
- (void)performActionForItem:(id)item
{
// Open your custom url assuming item is actually searchString
}
Run Code Online (Sandbox Code Playgroud)