I fill the tracks array with the setter I typed just before (with the reloadData) and then I have the NSTableViewDataSource extension to set the number of lines :
func numberOfRows(in tableView: NSTableView) -> Int {
if let tracks = tracks {
print("V&G_FW___numberOfRows : ", self, tracks.count)
return tracks.count
}
return 0
}
And in the NSTableViewDelegate extension I just get the tracks array for each track :
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
if let theTracks: [ITLibMediaItem] = tracks as? [ITLibMediaItem] {
let theItem = theTracks[row]
let cellIdentifier: String = "TracksListCellID"
var text: String = ""
switch tableColumn?.identifier.rawValue {
case TableColumnID.trackNumberTableColumnID.rawValue:
text = String(row + 1)
case TableColumnID.titleTableColumnID.rawValue:
text = getTrackTitle(theTrack: theItem)
case TableColumnID.artistTableColumnID.rawValue:
text = iTunesModel.getArtistName(theITTrack: theItem)
case TableColumnID.albumTableColumnID.rawValue:
text = iTunesModel.getAlbumTitle(theITTrack: theItem)
case TableColumnID.locationTableColumnID.rawValue:
text = theItem.location?.path ?? ""
case TableColumnID.totalTimeTableColumnID.rawValue:
text = getTotalTime(theTrack: theItem)
default:
text = ""
}
if let cell: NSTableCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: nil) as? NSTableCellView {
cell.textField!.stringValue = text
return cell
}
}
print("V&G_FW___viewFor tableColumn : ", self, "no TitleCellID is present !")
return nil
}
So classic code.
My problem is I think I need to call the reloadData each time I delete an item in the TableView at the bottom to refresh the view... Right ?
Topic:
Programming Languages
SubTopic:
Swift
Tags: