2012-11-16 15 views
0

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 &quot;Browse All&quot; 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幫助」都會變灰。

+0

我從NIB文件中刪除了幫助菜單項,然後在Xcode中準備好了。因爲我不明白的原因,幫助菜單啓用。以下代碼使Help Viewer出現: – mbarron

回答

1

我從NIB文件中刪除了幫助菜單項,然後將其重新添加到Xcode中。因爲我不明白的原因,幫助菜單啓用。下面的代碼所做的幫助查看器顯示:

- (IBAction) showHelp:(id)sender { 

     int status = MyGotoHelpPage(); 
     DLog(@"status for HelpBook load is %d",status); 
    } 

    OSStatus MyGotoHelpPage (void) 
    { 
     CFBundleRef myApplicationBundle = NULL; 
     CFStringRef myBookName = NULL; 
     OSStatus err = noErr; 

     myApplicationBundle = CFBundleGetMainBundle();// 1 
     //if (myApplicationBundle == NULL) {err = fnfErr; goto bail;}// 2 
     myBookName = 

CFBundleGetValueForInfoDictionaryKey(myApplicationBundle,CFSTR( 「CFBundleHelpBookName」));
if(myBookName == NULL){err = fnfErr;返回錯誤;}

 if (CFGetTypeID(myBookName) != CFStringGetTypeID()) {// 4 
      err = paramErr; 
     } 

     err = AHGotoPage (myBookName, NULL,NULL);// load title page 
     return err; 
    } 

幫助查看器顯示消息:「所選主題​​當前不可用。」 這是進步。

+0

可悲的是,這有時非常有效。謝謝。你幫我了 – jiminybob99