Display tooltip when user clicks a table row

All,
I have a single column table which has a fixed width. I fetch data from a text file and display this in the table.
Sometimes the row data doesn’t fit in the set width, so the complete information is not visible. I don’t want to display a horizontal scroller. I want to display a tooltip when user clicks such a row. The tip will then display the complete data. I can access the row data, but I’m not able to show a tooltip when user clicks the row. Here is my code

on tableRowClicked()
        if adataTable's selectedRow as integer is not equal to -1 then
            set rowSel to  (adataTable's selectedRow as integer)
            set rowSel to (rowSel + 1)
            set theRowData to item rowSel of theData
            --theData is a list bound to the Array Controller (From Simple Table Example of shane's book)
            
        end if    
end tableRowClicked 

on awakeFromNib()
        -- some statements
        adataTable's setAction_("tableRowClicked")
end awakeFromNib

Which method do I use to display a toltip when user click’s the row? I tried using setToolTip method and got an error.

[NSTextFieldCell setToolTip:]: unrecognized selector sent to instance 0x400da2d00

Hi,

a tooltip is supposed to be displayed when the user pauses the mouse a few seconds on an UI element.
To manage tooltips in a table view implement tableView_toolTipForCell_rect_tableColumn_row_mouseLocation_()

Just keep in mind that you automatically get one for each cell already.

Stefan,
So I have the following properties declared in my code

 property theDatacell : missing value --- Hooked to the  data Cell
 property theDataCol : missing value --- Hooked to the data Column


on tableRowClicked()
if adataTable's selectedRow as integer is not equal to -1 then
set rowSel to (adataTable's selectedRow as integer)
set rowSel to (rowSel + 1)
set theRowData to item rowSel of theData
--theData is a list bound to the Array Controller (From Simple Table Example of shane's book)


tableView_toolTipForCell_rect_tableColumn_row_mouseLocation_(adataTable,theDatacell, rect,theDataCol,rowSel, mouseLocation)
end if 
end tableRowClicked 

How do I pass the values rect and mouseLocation to this function ? It seems to be a struct data type from Xcode docs.

Found it in Shane’s book. Will try if it works now

Any idea why this doesn’t work and throws an error:

tableView_toolTipForCell_rect_tableColumn_row_mouseLocation_(adataTable,theDatacell,{{50,800},{600,400}},theDataCol,rowSel,{48,200})

[AppDelegate tableView:toolTipForCell:rect:tableColumn:row:mouseLocation:]: unrecognized selector sent to object <AppDelegate @0x4001ada60: OSAID(8)>
2012-02-10 15:04:46.771 MyApp[1245:707] *** -[AppDelegate tableRowClicked]: *** -[AppDelegate tableView:toolTipForCell:rect:tableColumn:row:mouseLocation:]: unrecognized selector sent to object <AppDelegate @0x4001ada60: OSAID(8)> (error -10000)

Have you made your app delegate also the delegate of the table?

Shane,
Looks like the theDatacell property is actually a NSTextFieldCell object and the method requires a NSCell object. I can’t seem to find the NSCell Object to hook the theDatacell property

All other connections are good.

I think you’re misunderstanding – tableView_toolTipForCell_rect_tableColumn_row_mouseLocation_ is a method you have to implement as a handler in the table’s delegate. The values are passed to you, and you have to return a suitable string.

But looking at the docs, rect is an NSRectPointer, and I don’t think you will be able to handle that in ASObjC anyway. So it may all be moot.

Learn to like the default tooltips :slight_smile:

Why is ASOC so frustrating at times :lol:

I’m still not sure of your problem. You say you have a single-column table; you should be getting the tooltip automatically when you hover over an overset cell. That’s how tooltips are supposed to work – by hovering, not selecting.

I have a single-column table whose rows are populated using data from a text file. Since the row data tends to get clipped coz of the set width, I want the row value as the tool tip. When I hover over a row(or cell ) I don’t see any tool tip. I thought I had to programmatically set the tooltip.

You keep saying rows, but what you’re talking about is cells. And what you describe is what happens by default.

Open the project from chapter 4 of my book, make the column very narrow, run it, and hover over a clipped entry. It should just work.

I’m not sure how you can turn that off. Perhaps setting a tooltip manually overrides things.