多个NSTableViews根据选择的TableView取消选择不同的单元格 - Swift OSX

时间:2016-03-28 02:55:14

标签: swift macos nstableview

对,所以我的视图中有2个NSTableViews,如果1选择了单元格,我希望对方没有选择,反之亦然,如果另一个选择了一个单元格,则另一个应该没有选择单元格。我怎样才能做到这一点?

这是我到目前为止所做的,但由于显而易见的原因,它无效。

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)
}

1 个答案:

答案 0 :(得分:3)

试试这个:

- (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];
    }

}

我有一个带有2个TableViews(table1,table2)的ViewController,并且每当选择table2时使用tableViewSelectionDidChange重新选择table1。 我在github上传了一个快速演示 https://github.com/tbass134/NSTableViewMutipleSelections