简体   繁体   中英

Swift - Why is argument item in NSOutlineView always nil?

I am attempting to implement a simple sourceView, however, I am only managing to set the stringValue of one textField.

First, this is the structure of my program:

class MainWindowController: NSWindowController, NSOutlineViewDataSource, NSOutlineViewDelegate
{
    @IBOutlet weak var sourceView: NSOutlineView!
    override func windowDidLoad()
    {
        sourceView.setDataSource(self)
        sourceView.setDelegate(self)
    }
}

Then, I have:

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

And finally,:

func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject
{...}

My issue is that in both of these functions, the value of item is nil. Is this what is supposed to happen?

It doesn't appear you're providing the object value. Unless you're using an NSTreeController to populate your NSOutlineView, you must also implement the data source function:

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

    // return your object value
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM