Chcę wdrożyć listę źródeł za pomocą NSOutlineView w projekcie Swift.Awaria NSOutlineView, gdy metoda delegowania isGroupItem jest używana ze Swiftem
Poniższy kontroler widoku działa dobrze, gdy metoda delegowania isGroupItem nie jest wywoływana. Jednak wiele elementów __NSMallocBlock__ zostanie zwróconych, gdy użyta zostanie metoda isGroupItem. Nie mam pojęcia, skąd pochodzą te elementy. Elementy, które podałem, są tylko ciągami.
class ViewController: NSViewController, NSOutlineViewDataSource, NSOutlineViewDelegate {
let topLevel = ["1", "2"]
let secLevel = ["1": ["1.1", "1.2"], "2": ["2.1", "2.2"]]
func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int {
if let str = item as? String {
let arr = secLevel[str]! as [String]
return arr.count
} else {
return topLevel.count
}
}
func outlineView(outlineView: NSOutlineView, isItemExpandable item: AnyObject) -> Bool {
return outlineView.parentForItem(item) == nil
}
func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
var output: String!
if let str = item as? String {
output = secLevel[str]![index]
} else {
output = topLevel[index]
}
return NSString(string: output)
}
func outlineView(outlineView: NSOutlineView, objectValueForTableColumn tableColumn: NSTableColumn?, byItem item: AnyObject?) -> AnyObject? {
return item
}
func outlineView(outlineView: NSOutlineView, isGroupItem item: AnyObject) -> Bool {
return (outlineView.parentForItem(item) == nil)
}
func outlineView(outlineView: NSOutlineView, viewForTableColumn tableColumn: NSTableColumn?, item: AnyObject) -> NSView? {
return outlineView.makeViewWithIdentifier("HeaderCell", owner: self) as NSTextField
}
}
Projekt próbki można pobrać here
Pachnie jak błąd. Jeśli zwrócisz 'true', to ulegnie awarii. Jeśli zwrócisz 'false', to pokazuje linię rodzica jako' malloc ... ' –
To prawdopodobnie jest błąd; powinien "po prostu działać", ale nie działa. Zobacz moją odpowiedź (wkrótce). –