NSOutlineView никогда не достигает детей источника данных
Swift 4, Xcode 9.1
Я могу получить только первый уровень предметов для рендеринга в моем NSOutlineView
, Дочерние элементы никогда не работают. Ниже мой код с комментариями, которые показывают, что регистрируется на консоли.
class SidebarSection{
var title:String!
var buttonHidden:Bool!
}
class SidebarItem{
var title:String!
}
loadStuff(){
print(sections) //[MyApp.SidebarSection, MyApp.SidebarSection]
print(items) //[[MyApp.SidebarItem, MyApp.SidebarItem, MyApp.SidebarItem], [MyApp.SidebarItem]]
sidebarOutlineView.reloadData()
}
//Over in my NSOutlineViewDelegate/Datasource...
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
print(item) //nil
print(sections) //[MyApp.SidebarSection, MyApp.SidebarSection]
if let section = item as? SidebarSection{
print("This never gets logged.")
//...
}else{
//Sections
print("Returned: \(sections.count)") //2
return sections.count
}
}
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
print("\(index) / \(item)") //First time: 0 / nil; Second time: 1 / nil
if let section = item as? SidebarSection{
print("This never gets logged, either.")
//...
}else{
//Items
return sections[index]
}
}
Я старался if let section = item as? SidebarSection{}
сразу после того, как мои данные будут добавлены в sections
массив, и он распознает тип просто отлично. Я не могу понять, что я делаю не так.
Есть идеи?