I am at a dead-end with my code. I have a cell-view NSTableView where I import a csv file. I would like to use the tableview as a Spreadsheet. If I hit the return key after editing the specific cell, it should move to the next row, highlight it and make it editable.
I have found code written in objective c but none works for me.
How do I do that? Hope somebody will be able to assist.
Thanks in advance.
Code I have:
func controlTextDidEndEditing(_ notification: Notification) {
let editedColumn: Int = tableMain.editedColumn
let editedRow: Int = tableMain.editedRow
let lastRow: Int = tableMain.numberOfRows
let lastCol: Int = tableMain.numberOfColumns
var userInfo = notification.userInfo
let textMovement = Int(truncating: userInfo?["NSTextMovement"] as? NSNumber ?? 0)
//super.textDidEndEditing(notification)
if textMovement == NSTabTextMovement {
if editedColumn != lastCol - 1 {
tableMain.selectRowIndexes(NSIndexSet(index: editedRow) as IndexSet, byExtendingSelection: false)
tableMain.editColumn(editedColumn + 1, row: editedRow, with: nil, select: true)
} else {
if editedRow != lastRow - 1 {
tableMain.editColumn(0, row: editedRow + 1, with: nil, select: true)
} else {
tableMain.editColumn(0, row: 0, with: nil, select: true) // Go to the first cell
}
}
} else if textMovement == NSReturnTextMovement {
if editedRow != lastRow - 1 {
tableMain.selectRowIndexes(NSIndexSet(index: editedRow + 1) as IndexSet, byExtendingSelection: false)
tableMain.editColumn(editedColumn, row: editedRow + 1, with: nil, select: true)
} else {
if editedColumn != lastCol - 1 {
tableMain.editColumn(editedColumn + 1, row: 0, with: nil, select: true)
} else {
tableMain.editColumn(0, row: 0, with: nil, select: true) //Go to the first cell
}
}
}
}