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 ?
Post
Replies
Boosts
Views
Activity
Thx for your answer.
I initialize the dataSource on the self (like often).
After that I set the tracks with a setter and I reload the datas :
`var tracks: [NSObject]? {
set {
datas = newValue
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in
self!.tracksListTableView.reloadData() // to avoid the init bug...
}
}
get {
if let tracks: [NSObject] = datas as? [NSObject] {
return tracks
}
return nil
}
}`
My bad but my project has 2 years old and I don't even remember how I plug the datas to the TableView... In the inspector ?
Thx.