Eli
Eli

Reputation: 768

Multiple NSTableViews Deselect different Cells depending on what TableView was Selected - Swift OSX

Right so i have 2 NSTableViews in my view, if 1 has cell selected i want the other to have none selected, and vise versa if the other one has a cell selected the other should have no cell selected. How can i achieve this?

This is what i have so far, but for obvious reasons its not working.

func tableViewSelectionDidChange(notification: NSNotification) {
 //this is how im deselecting rows from the other table view but the reset i cant make work
    DayTableView.selectRowIndexes(NSIndexSet(), byExtendingSelection: false)
}

Upvotes: 1

Views: 380

Answers (1)

Tony
Tony

Reputation: 664

Try this:

- (void)tableViewSelectionDidChange:(NSNotification *)notification {
    if ([notification object] == self.table1) {
    } else {
        NSTableRowView *myRowView = [self.table1 rowViewAtRow:self.table1.selectedRowIndexes.lastIndex makeIfNecessary:NO];
        [myRowView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleRegular];
        [myRowView setEmphasized:YES];
        [self.table1 selectRowIndexes:self.table1.selectedRowIndexes byExtendingSelection:NO];
    }

}

I have a ViewController with 2 TableViews(table1, table2) and using tableViewSelectionDidChange to reselect table1 whenever table2 is selected. I uploaded a quick demo on github https://github.com/tbass134/NSTableViewMutipleSelections

Upvotes: 3

Related Questions