I have setup a NSView with an embedded NSTableView.
I have tried to set an action for the NSTableViewCell to run when a change is made to the Table View Cell:
import Cocoa
class MyView: NSView
{
override func drawRect(dirtyRect: NSRect)
{
super.drawRect(dirtyRect)
}
@IBAction func valEntered2(sender: AnyObject)
{
Swift.print("valueEntered2")
}
}
Although this approach has worked fine previously when using a NSViewController on a storyboard, when I compile this code it gives a warning:
Action 'valEntered2:' sent by 'Table View Cell' is connected to 'View', an invalid target (Objects inside view based table views they only be connected to the table view's delegate.)
So it seems that it doesn't like the action being in the the NSView so I have subclassed NSTableView so I can move it there instead:
class MyTable: NSTableView, NSTableViewDataSource, NSTableViewDelegate
{
let appDelegate = NSApplication.sharedApplication().delegate as! AppDelegate
override init(frame frameRect: NSRect)
{
super.init(frame: frameRect)
}
required init?(coder: NSCoder)
{
super.init(coder: coder)
self.setDataSource(self)
self.setDelegate(self)
}
override func drawRect(dirtyRect: NSRect)
{
super.drawRect(dirtyRect)
}
func numberOfRowsInTableView(tableView: NSTableView) -> Int
{
return 5
}
func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView?
{
let cell: NSTableCellView = tableView.makeViewWithIdentifier(tableColumn!.identifier, owner: self) as! NSTableCellView
cell.textField!.stringValue = "Hello World"
return cell
}
}
I have setup the table in the view to use this class:
I would have expected this to be the delegate for this NSTableView and to be able to add the TableViewCell's action to MyTable but it refuses to create the action.
What steps have I missed?