OS X,为什么帮助NSMenuItem在MAINMENU注册帮助书OS X,注册帮助手册后,为什么NSMenu中的NSMenuItem帮助被禁用? OSX,HelpBook,NSMenuItem,AHRegisterHelpBookWithURL</p> <p>的HelpBook是不可用,因为在帮助菜单被禁用:
标签后被禁止。 当选择了帮助菜单,帮助子菜单出现这样:
Spotlight Search searchBar here - BLUE
HungryMe Help - GREYED OUT
的MainWindow.nib包含菜单。帮助菜单项在Xcode中启用。
帮助书
HelpBook Info.plist如下;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en_US</string>
<key>CFBundleIdentifier</key>
<string>com.DrummingGrouse.HungryMe.help</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>HungryMe</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>hbwr</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>HPDBookAccessPath</key>
<string></string>
<key>HPDBookIconPath</key>
<string>shrd/EyeOnly.png</string>
<key>HPDBookIndexPath</key>
<string></string>
<key>HPDBookKBProduct</key>
<string></string>
<key>HPDBookKBURL</key>
<string></string>
<key>HPDBookRemoteURL</key>
<string></string>
<key>HPDBookTitle</key>
<string>HungryMe Help</string>
<key>HPDBookType</key>
<string>3</string>
</dict>
</plist>
测试扉页HungryMe.html,如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" AppleTitle="com.DrummingGrouse.HungryMe.help" />
<title>HungryMe</title>
</head>
<body>
<a name="hungryme_page"></a>
<div class="container">
<p>This is some text. <img src="../shrd/EyeOnly.png" align="middle"> This is some more text.</p>
<div class="content">
<h1>Getting Started - Cooking with HungryMe</h1>
<p>HungryMe has a main window with Category elements on the left and Recipe elements on the right.</p>
<p>The display of a recipe's details is done as follows:</p>
<p> 1. Select a recipe Category in the left table of the main window. Select "Browse All" if you wish to have all recipes to be listed.</p>
<p>2. Double click the desired recipe and a separate window will appear displaying the details for the selected recipe. Multiple recipes can be displayed simultaneously.</p>
<!-- end .content --></div>
<!-- end .container --></div>
</body>
</html>
应用程序的Info.plist有:
CFBundleHelpBookFolder HungryMe.help CFBundleHelpBookName com.DrummingGrouse.HungryMe.help
Apple帮助编程指南有:
The CFBundleHelpBookName key identifies the help book. The value associated with this key
should be a string specifying the help book title, as defined by the AppleTitle tag in the
title page of the book. For example, here is how you would enter the title
of the SurfWriter Help book:
<key>CFBundleHelpBookName</key>
<string>com.mycompany.surfwriter.help</string>
帮助手册捆绑HungryMe.help被添加到Xcode项目的资源/文件夹中。 的包的结构是这样的:
HungryMe.help/
Contents/
Info.plist
Resources/
shrd/ <shared artwork>
English.lproj/
HungryMe.html <title page>
pgs/ <the rest of the content pages>
gfx/ <localized artwork>
sty/ <style sheets, generated list template>
scrpt/ <scripts>
的帮助菜单项,将显示HelpBook是灰色的 帮助书是否被使用AHRegisterHelpBookWithURL注册。
如果使用AHRegisterHelpBookWithURL,则在下面的代码中返回的err为零。
OSStatus RegisterMyHelpBook(void)
{
CFBundleRef myApplicationBundle;
CFURLRef myBundleURL;
OSStatus err = noErr;
myApplicationBundle = NULL;
myBundleURL = NULL;
myApplicationBundle = CFBundleGetMainBundle();// 1
if (myApplicationBundle == NULL) {err = fnfErr; return err;}
myBundleURL = CFBundleCopyBundleURL(myApplicationBundle);// 2
if (myBundleURL == NULL) {err = fnfErr; return err;}
if (err == noErr){
err = AHRegisterHelpBookWithURL(myBundleURL);// 3
}
return err;
}
下面的代码,在启动时执行,
NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu];
NSMenuItem *menuItemHelp = [mainMenu itemWithTitle:@"Help"];
NSMenu *menuHelp = [menuItemHelp submenu];
NSMenuItem *menuItemHelpHungryMe = [menuHelp itemAtIndex:0];
DLog(@"menuItemHelpHungryMe=%@",menuItemHelpHungryMe);
DLog(@"menuHelp=%@",menuHelp);
产生以下输出。
2012-11-16 11:30:03.167 HungryMe[62153:303] -[AppDelegate applicationDidFinishLaunching:]
menuItemHelpHungryMe=<NSMenuItem: 0x1b6e3c0 HungryMe Help>
2012-11-16 11:30:03.168 HungryMe[62153:303] -[AppDelegate applicationDidFinishLaunching:]
menuHelp=<NSMenu: 0x1b6e3a0>
Title: Help
Supermenu: 0x1b6c8e0 (MainMenu), autoenable: YES
Items: (
"<NSMenuItem: 0x1b6e3c0 HungryMe Help>"
)
我发现上面的menuHelp只有一个项目。
无论是否在NIB中启用了帮助菜单 ,帮助菜单项目标题为“HungryMe帮助”都会变灰。
我从NIB文件中删除了帮助菜单项,然后在Xcode中准备好了。因为我不明白的原因,帮助菜单启用。以下代码使Help Viewer出现: – mbarron