chuckhoupt / jekyll-apple-help

Easily create Apple Help-Books for your Mac OS X app using this Jekyll template and build system.
MIT License
188 stars 17 forks source link

Anchors #16

Closed jmoukel closed 7 years ago

jmoukel commented 7 years ago

Hi guys,

How can I set an anchor in a page so I can open the Help Book programmatically (using [[NSHelpManager sharedHelpManager] openHelpAnchor:inBook:]) in that specific anchor?

chuckhoupt commented 7 years ago

Hi @jmoukel,

To programmatically open a help page, first add an anchor identifier to the page's front matter. For example test-help.md:

---
title: Test Help
anchor: test-help
---

This is some test help.

Next, in your Interface Builder file, add a Help Button (an NSButton with Style 'help') and connect its action to a method like the following which will open the 'test-help' anchor:

- (IBAction)showAnchorHelp:(id)sender {
    NSString *locBookName = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"];
    [[NSHelpManager sharedHelpManager] openHelpAnchor:@"test-help" inBook:locBookName];
}

That should be it. Let me know if you run into a problem.