slashlos
slashlos

Reputation: 933

detecting clicked tableView

Regardless of selection, I need to know the tableview involved with a mouse click. Consider

func tableViewSelectionDidChange(notification: NSNotification) {
    self.selectedTableView = (notification.object as! NSTableView)
    switch selectedTableView {
    case oneTableView?:
        print("one")
        break
    case twoTableView?:
        print("two")
        break
    default:
        print("wtf \(selectedTableView)")
    }
}

table/view 'two' is a detail of 'one'. Selecting a row in 'one' alters the content for tableview 'two' (header -> detail). But if the user clicked a row already selected, no notification as the selection did not change. Basi I just need to know the last tableview / column clicked.

Is mouseDown approach better (way more difficult) but I do not see objective-c or 'UI' equivalent delegate methods in the AppKit -> NSTableView -> NSTableView for column or row selection methods?

Upvotes: 0

Views: 640

Answers (2)

slashlos
slashlos

Reputation: 933

Well, on osx in the current AppKit (8.2.1) state on Sierra this is not doable.

My gui is using a single action control for a set of header/detail tableViews and I needed to know which was in effect, so I'm to mandating an empty selection in the detail table view to indicate the header view selection is to be used.

But I would like to know why osx swift doesn't have a comparable delegate method set that ios or objective-c have?

Upvotes: 0

Jay
Jay

Reputation: 2661

What you should do is, within this UITableViewDelegate Function:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if let tableOne = tableView as? TableOne {// do code here to other table}
    else if let tableTwo = tableView as? TableTwo {//do code here to other table}
}

Upvotes: 0

Related Questions