Quincey,
Thanks for the reply.
At the time of my original posting I had verified several times that all the
protocol functions got called and were returning the values I expected them to
return. The objectValueForTableColumn one was returning a String, the title I
hoped would appear in the outline.
Following Ken’s advice, I changed that method to return the node itself, not
its title, and tried changing a binding to read the title. It appears messing
with the bindings perturbed the system somehow: now the
objectValueForTableColumn method doesn’t seem to ever get called. The protocol
has four methods, and the other three still do get called and return the values
I expect.
That’s a long answer to your question about whether the method ever gets
called. In summary: it was once called and returned a good String value; now it
would return a good DocumentNode object from which the String title could be
retrieved, but it isn’t called for some reason; and either way, there’s no
visible difference in the running app. I still get a fully populated document
tree where each node’s title is blank.
Here is my Document object’s current code. For brevity I have cut out the
boilerplate methods generated by Xcode and not yet modified by me.
import Cocoa
class Document: NSDocument, NSOutlineViewDataSource {
@IBOutlet weak var theOutlineView: NSOutlineView!
var theProject: DocumentNode
override init() {
// Swift requires local properties to be initialized first
theProject = DocumentNode.CreateSampleProject()
super.init()
}
func getDocumentNodeFrom( obj: AnyObject! ) -> DocumentNode {
if let node = obj as? DocumentNode {
return node
} else {
return self.theProject
}
}
func outlineView(
nsov: NSOutlineView!,
child index: Int,
ofItem item: AnyObject!
) -> AnyObject!
{
let node = getDocumentNodeFrom( item )
let result = node.children[ index ]
return result
}
func outlineView(
nsov: NSOutlineView!,
isItemExpandable item: AnyObject!
) -> Bool
{
let count = outlineView( nsov, numberOfChildrenOfItem: item )
let result = count > 0
return result
}
func outlineView(
nsov: NSOutlineView!,
numberOfChildrenOfItem item: AnyObject!
) -> Int
{
let node = getDocumentNodeFrom( item )
let result = node.children.count
return result
}
func outlineView(
nsov: NSOutlineView!,
objectValueForTableColumn tableColumn: NSTableColumn!,
byItem item: AnyObject!
) -> AnyObject!
{
let node = getDocumentNodeFrom( item )
return node
}
}
—
Charles Jenkins
On Tuesday, September 9, 2014 at 15:28, Quincey Morris wrote:
> Actually, I was wrong. Because the protocol has the underscore (followed by a
> space to separate it from the parameter name), it doesn’t matter what you use
> for your parameter name in your declaration — _outlineView, outlineView and
> xxx would all have been fine.
>
> However, your solution to the problem (the warning message, that is) was
> pretty lousy. It wasn’t the space that was extraneous, it was the underscore,
> and the natural solution would be to remove the underscore. (That is, unless
> you *like* having variable name start with an underscore.)
>
> Back to the original problem, assuming you haven’t already found what’s wrong:
>
> You need to approach this systematically. Is the method called at all? Does
> ‘getDocumentNodeFrom’ return a non-nil value? What is the actual value of the
> ‘title’ property?
>
>
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]