1

I have a NSTableViewwith a NSImageCellin it. I would like to add a tooltip that when I hover the image with the mouse i get a tooltip with the Path of the image. What is the best way to do this?

the problems I have are these:

  • retrive the path of the hovered image
  • display it in the tooltip

please keep your answers easy, I am a newbie.

---EDIT---

additional info: myarray.arrangedobjects is what fills the table. it is an array of NSMutableDictionaries. the dictionary has following Keys:

  • image (the one displayed in the table that i would like to place the tooltip over)
  • imagepath (the text i would like to display in the tooltip)
  • filename (is displayed in another cell)
sharkyenergy
  • 3,842
  • 10
  • 46
  • 97

1 Answers1

5

You will need to provide a delegate for the NSTableView and implement this delegate method:

– tableView:toolTipForCell:rect:tableColumn:row:mouseLocation:

You can find the docs for the NSTableViewDelegate protocol here. You need to make sure to plug the delegate into the delegate outlet on the NSTableView using IB. Your method will not be called unless that has been done. Also, it's worth noting that this delegate method is called on demand, not up-front, so it wont get called until you've parked your mouse hovering over a cell. This approach should work for both tables with a data source and tables that use bindings.

I put a trivial example up on GitHub.

ipmcc
  • 29,581
  • 5
  • 84
  • 147
  • hello! :)i am using bindings.. with an arraycontroller.. will this work anyway? – sharkyenergy Feb 22 '13 at 20:09
  • Assuming you can figure out how to generate the tool tip based on the parameters of that method, yeah, it'll work. – ipmcc Feb 22 '13 at 21:06
  • thanks! i implemented the `NSTableViewDelegate` protocol, but the method you mention is never called... i have set a breakpoint in it but no matter what i do it doesnt break.. what am i missing? – sharkyenergy Feb 23 '13 at 09:45
  • @Justme: I've updated my answer with some additional tips and a working sample project. – ipmcc Feb 25 '13 at 17:23
  • cant seem to find a way to download the example. never used github. mind telling me? thanks – sharkyenergy Feb 25 '13 at 17:32
  • yay it works! can award bount only in 18 hours tough! will do it Tomorrow! thanks! by the way, is it possible to make it appear sooner? to shorten the delay of the tooltip? – sharkyenergy Feb 25 '13 at 17:44
  • Found! for who might need it: `// Alter tooltip delay setting [[NSUserDefaults standardUserDefaults] setObject: [NSNumber numberWithInt: 50] forKey: @"NSInitialToolTipDelay"]; ` – sharkyenergy Feb 25 '13 at 18:05