You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The NSTableView extension doesn't apply section changes and indices assume a single section.
Motivation and Context
Like the UITableView, NSTableView supports sections (called "group rows" in AppKit). It would be great if they would just work in combination w/ ArraySection's.
Proposed Solution
In NSTableView the sections (group rows) are part of the collection feed to the tableview. E.g.
It's not obvious that this isn't supported. Maybe AppKitExtension.swift should have
assert(changeset.sectionInserted.isEmpty,
"srz, section updates not yet supported on AppKit!")
...
in the reload.
Not quite sure about the best way to implement this. The reload should have all the grouping information necessary. Essentially there would need to be a separate step adjusting the indices to the flat ones, while applying the changes.
Sample TV datasource/delegate on top of ArraySection
extensionAppDelegate:NSTableViewDelegate{func tableView(_ tv:NSTableView, isGroupRow row:Int)->Bool{switch test.data[flat: row]{case.some(.model):returntruedefault:returnfalse}}func tableView(_ tv:NSTableView, viewFor tc:NSTableColumn?, row:Int)->NSView?{letlabel=NSTextField(labelWithString: test.data[flat: row]?.stringValue ??"-")return label
}}extensionAppDelegate:NSTableViewDataSource{func numberOfRows(in tableView:NSTableView)->Int{
test.data.flatCount
}}finalclassSectionedTest{vardata=[ArraySection<String,String>]()func applyNewData(_ newValue:[ArraySection<String,String>],
on tableView:NSTableView){letchangeset=StagedChangeset(source: data, target: newValue)
tableView.reload(using: changeset, with:.effectFade){ newValue inself.data = newValue
}}}enumRow{case model(String)case element(String)varstringValue:String{switchself{case.model(let s),.element(let s):return s
}}}extensionCollectionwhere Element ==ArraySection<String,String>{varflatCount:Int{reduce(0){ $0 +1+ $1.elements.count }}
subscript(flat index:Int)->Row?{varcursor=0forsectioninself{if cursor == index {return.model(section.model)}
cursor +=1if cursor > index {break}letoffset= index - cursor
assert(offset >=0)if offset < section.elements.count {return.element(section.elements[offset])}
cursor += section.elements.count
}assertionFailure("index out of range \(index)\(count)")returnnil}}
The text was updated successfully, but these errors were encountered:
@helje5
The data structure isn't compatible with section and group rows cuz the concepts are different, so I think it won't be able to support NSTableView.
Checklist
Description
The NSTableView extension doesn't apply section changes and indices assume a single section.
Motivation and Context
Like the UITableView, NSTableView supports sections (called "group rows" in AppKit). It would be great if they would just work in combination w/ ArraySection's.
Proposed Solution
In NSTableView the sections (group rows) are part of the collection feed to the tableview. E.g.
Is presented to NSTableView as:
It's not obvious that this isn't supported. Maybe AppKitExtension.swift should have
in the
reload
.Not quite sure about the best way to implement this. The
reload
should have all the grouping information necessary. Essentially there would need to be a separate step adjusting the indices to the flat ones, while applying the changes.Sample TV datasource/delegate on top of
ArraySection
The text was updated successfully, but these errors were encountered: