简单的NSOutlineView保留崩溃

时间:2016-03-10 19:06:39

标签: swift macos nsoutlineview

我的OSX Swift项目中有一个简单的NSOutlineView设置从一个基本数组中提供,但它导致EXC_BAD_ACCESS崩溃。

启用僵尸后,它崩溃并出现以下错误: [NSMutableIndexSet retain]: message sent to deallocated instance

Heeeelp!这是我的代码:

class SidebarViewController: NSViewController, NSOutlineViewDataSource {

    //MARK: Vars

    @IBOutlet var sidebar : NSOutlineView?
    var data : [String] = ["Assemblies", "Parts", "Customers"]


    //MARK: Init

    override func viewDidLoad()
    {
        super.viewDidLoad()
        // Do view setup here.
    }


    //MARK: NSOutlineView Delegate / Datasource

    func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int
    {
        return data.count
    }

    func outlineView(outlineView: NSOutlineView, isItemExpandable item: AnyObject) -> Bool
    {
        return false
    }

    func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject
    {
        return data[index]
    }

    func outlineView(outlineView: NSOutlineView, objectValueForTableColumn tableColumn: NSTableColumn?, byItem item: AnyObject?) -> AnyObject?
    {
        return item
    }
}

1 个答案:

答案 0 :(得分:0)

原来objectValueForTableColumn方法需要返回obj_c个对象。因此,在我的数组中返回String不起作用。我将其更改为NSString,现在可以使用了。