Hi Claude31,
Yes, as I said in my post, the tableview appears to function as it should in all other respects.
Post
Replies
Boosts
Views
Activity
@Claud31 thanks.
Yes, the delegate (and datasource) have been set for the TableView to my ViewController. I'll add that the tableview is cell based.
For my action I've tried NSTextField, NSTextFieldCell and even Any – with no success.
My IBAction code (there's nothing in it yet):
@IBAction func cellWasEdited(_ sender : NSTextFieldCell) { print("cell was edited") }
I'm using a cell based NSTableView.
I tried what you posted but it didn't work – I imagine that's because your example is for a view based TableView?
Here is the ViewController code for a test project that demonstrates the issue I'm having with my actual project:
(Is there a way to attach the entire Xcode project?)
`//
// ViewController.swift
// TEST
//
// Created by Phil Bond on 9/13/21.
//
import Cocoa
class ViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
var infoForTableView : [String] = ["one", "two", "three", "four", "five"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
@IBAction func cellWasEdited(_ sender: NSTextFieldCell) {
print("cell was edited")
print(sender.stringValue)
}
func numberOfRows(in tableView: NSTableView) -> Int {
return infoForTableView.count
}
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
return infoForTableView[row]
}
}
`
Ah yes... thank you.
When I switch the tableview type to view based I can edit the cell but I still want to have that editing trigger an action so that I can act on the changes.
"Yes, view based is much simpler"
Better maybe, but simpler? ;-)
In any case, is there a way for the edited cell to trigger an action in the view controller so that I can act on any changes that were made?
I must have figured this out about the same time your comment came in. That's exactly what I ended up doing.
Thank you!