Set contents on NSTableViewCell depending on NSPopUpButton

321 views Asked by At

i was just wondering how to set a NSTableCellView to show a specific string depending on what option a user selected from a NSPopUpButton, any and all help would be greatly appreciated…

I would like to do this without using binding also

2

There are 2 answers

0
Cowirrie On BEST ANSWER

First, make sure you understand the Model-View-Controller design pattern. You need to do three things:

  1. Create a data structure to store your model.
  2. Have the NSTableView display the state of the model.
  3. Have the NSPopUpButton change the model.

Also, why do you want to do this without bindings? Bindings are often simpler and easier than creating your own NSTableViewDataSource. For some complex problems you have to do the work yourself, but if bindings will solve the problem, they are often the best solution.

0
pbx On

Maybe I dont understand you correctly but wouldnt it be the easiest way to just implement what is needed for NSTableViewDataSources, that is

-numberOfRowsInTableView
-tableView:objectValueForTableColumn:row

and return to your Table View, what might be needed. As far as I know, this even works with your NSTableCellView.

You could use the IBAction your Button causes and use

reloadData

on the Table View.

By the way, usually Table Views are intended to show large amounts of data. If you only want to show a short statement depending on the button selection consider using a NSTextField instead.