NSPopover from NSToolbarItem

Recently, when working on the next release of iSMARTtrain, I wanted to display an NSPopover containing the various options when a button in the toolbar was clicked. I mean, how hard can that be? – I’d already done it in the iPad version of Ergophase. Trivial!

NSPopover from NSToolbarItem

Three hours later, it turns out, it’s not as straight-forward as I thought. Central to displaying an NSPopover is the following method call:-

 (void)showRelativeToRect:(NSRect)positioningRect ofView:(NSView *)positioningView preferredEdge:(NSRectEdge)preferredEdge

Surely all I need to do is to get the view from the Toolbar button, pass it to this method, the popover’s displayed, and all is good with the world?

Well, unfortunately not.

For whatever reason, NSToolbarItem is inherited from NSObject, rather than NSControl, meaning that it has no View property that can be accessed (well, actually it does, but for the default button added in IB, view always returns Nil).

I posted my problem in Stackoverflow and, unusually, got no solution. Searching Apple’s developer forums turned up this post (http://devforums.apple.com/message/499986), which refered me to one of this year’s WWDC videos.

Once I’d seen that, everything became a bit clearer. The solution is to create an NSToolbarItem with a custom view containing an NSButton. When the button is clicked, pass the View of the button to the showRelativeToRect method, displaying the popover.

In the spirit of  http://xkcd.com/979, I’m posting a really simple example with the code on github (http://github.com/tevendale/ToolbarPopover). One slight issue with the current code is the way the button behaves when clicked, but I’m sure someone smarter than me will manage to fix that.

YFCalendarView – iPad Calendar Framework

YFCalendarView is our open-source framework for a full-screen iPad calendar. It’s loosely based on the Mac calendar framework LRCalendar (which seems to have largely disappeared from the ‘net).

It provides a full-screen monthly calendar, functionally similar to the iPad Calendar app ‘Month’ view.


Download the latest code from our Github repository: http://github.com/tevendale/YFCalendar

iOS Debugging with Hardware

dockstubz from CableJive

If you’re developing an app which uses hardware that plugs into the 30-pin Dock Connector of the iPhone or iPad, then debugging in Xcode can become a bit of a problem. I’m working with Wahoo Fitness using their Fisica ANT+ device at the moment, and I was about to break out the soldering iron to make some sort of a pass-through connector when Chip from Wahoo mentioned using dockStubz from Cablejive.

This provides a male and female dock connector with a USB connector in the middle of the unit. This lets the iOS device be connected to a Mac with the hardware device installed, allowing breakpoints and the like to be set in Xcode.

It’s available directly from Cablejive in the US and from Amazon in the UK (and presumably the rest of Europe).

Installing Core Plot in a Mac Application

I’ve started using the Core Plot framework in one of my Mac apps, and I had a few problems setting it up, which, looking through some posts on the web, other users have had as well. Since it took a while for me to track down the exact solution to my problem, I’m posting in here in the hope that it’ll save some other users the time I spent on it.

Firstly, a word or two about Core Plot. The framework in a data visualisation (aka graphing) solution created by primarily by Drew McCormack, with input for several other people. Basically, it lets you create line, bar and pie charts in a cocoa app with minimal effort.

I’d previously used Core Plot in a couple of iPhone & iPad apps, and managed to install it without any problems. However, when installing it in my Mac app by following the instructions on the website (http://code.google.com/p/core-plot/wiki/UsingCorePlotInApplications) I was met with a string of compiler errors related to Core Plot classes.

After checking my installation and making sure that search paths, etc., were all set to point to the Core Plot folder, it became apparently that something else was amiss. Searching through a number of posts on the web and the Core Plot site, and poking though a couple of Apple documents, it became apparent that one vital step missing from the docs was to set the build folder in the CorePlot.xcodeproj to match the build folder of the actual project containing it. This is done by double clicking on the CorePlot.xcodeproj project item embedded in your project, then selecting ‘Get Info’ from the project item’s contextual menu. This will display the Project Info window. Select the ‘Build’ tab. In the ‘Build Products Path’, set the location of the parent project’s build folder.

CorePlotLocation.png CorePlotContextualMenu.png


Hopefully, the information here will save someone else a bit of time setting up Core Plot.