1

I have popup button and nstableview. When I switch items in popup button the content of table should change. I have for each item in popup button the arrays which should be displayed in nstableview. I guess in two functions:

(numberOfRowsInTableView(tableView: NSTableView) -> Int
tableView(tableView: NSTableView, viewForTableColumn tableColumn:
                NSTableColumn?, row: Int) -> NSView?

I have to use if conditions to choose correct array. Question is what I have to write in these if conditions indicating the popup item? Or, am I going in wrong direction ?

VYT
  • 1,071
  • 19
  • 35

1 Answers1

1

At the end of the day I have found out the solution. I hope it will be useful for beginners like me. My code is below.

 var selectedContentOfTable = Int()

 @IBAction func chooseContentOfTable(sender: AnyObject)
 {
    selectedContentOfTable = (sender as! NSPopUpButton).indexOfSelectedItem
    myTable.reloadData()
 }

 func numberOfRowsInTableView(tableView: NSTableView) -> Int
 {
     ...
     if  selectedContentOfTable == 0 //for upper popup item 
     {
         //your code for particular tableview content
     }else if selectedContentOfTable == 1 //for next down popup item
     {
         //your code for particular tableview content 
     }
     ...
 }

 func tableView(tableView: NSTableView, viewForTableColumn tableColumn:
            NSTableColumn?, row: Int) -> NSView?
 {
     ...
     if  selectedContentOfTable == 0 //for upper popup item 
     {
         //your code for particular tableview content
     }else if selectedContentOfTable == 1 //for next down popup item
     {
        //your code for particular tableview content
     }
     ...
 }
VYT
  • 1,071
  • 19
  • 35