简体   繁体   中英

How to get a cell value from NSTableView in Cocoa?

I have probably a dumb question, but Im pretty new to Cocoa, so I don't feel bad asking it :)

I have a tableview filled with some numeric values. What I need is that when the user clicks on a particular cell some action happens involving this cell value.

For example: table has values from 1 to 10, user clicks on a value and the square of this value appears somewhere on the window. (user clicks on 3 and 9 appears somewhere next to the table)

I will really appreciate any help!

Thank you!

First of all set your app delegate to be the delegate of the table view (use the setDelegate method).Then declare your app delegate to implement the NSTableViewDelegate protocol (probably you've already done this - If not, add NSTableViewDelegate after NSApplicationDelegate).
Then implement this method:

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification;

This way you are noticed whenever the selection of the table view changes (use table view's selected row method to know which row has changed).
There are also a lot of method that you can implement in the NSTableViewDelegate, to be noticed when other events occur.

PS: Not dumb question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM