Re: [Pyobjc-dev] Object not being identified correctly?
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-05-26 05:18:00
|
On Monday, May 26, 2003, at 02:20 Europe/Amsterdam, Sean Gilbertson wrote: > Hello all, > > I am using an NSOutlineView to display a hierarchy of data, so Cocoa > asks for items, and then later gives them back to me, looking for the > number of children, and "value" ("label") for the data, which it draws > onto the UI. My problem is that, when Cocoa gives the item back to > me, the "in" test fails. Take a look at the following code "snippet," > and its results: > > def outlineView_isItemExpandable_( self, outlineView, item ): > NSLog( "isItemExpandable: %s" % ( item ) ) > > NSLog( "item in self.profiles: %s" % ( item in self.profiles ) > ) > > for profile in self.profiles: > NSLog( "%s" % ( profile ) ) > > Results: > > 2003-05-25 20:09:04.427 Bluebeard2[5819] isItemExpandable: > <ServerInformation.ServerInformation instance at 0x8cfac0> > 2003-05-25 20:09:04.429 Bluebeard2[5819] item in self.profiles: 0 > 2003-05-25 20:09:04.431 Bluebeard2[5819] > <ServerInformation.ServerInformation instance at 0x8cfac0> > > As you can see, the objects share the same reference address. > Performing similar actions in the Python interpreter works fine ("in" > tests return True). I've also tried, in the "for profile in > profiles:" loop, "==" and "is" tests, which both return False. Can > anyone shed some light onto why this is happening? Are the items instances of (a subclass of) NSObject? You must use subclasses of NSObject as items for NSOutlineViews, and you must keep the items alive as long as the view might reference them. NSOutlineView cheats a little and stores the items in an internal datastructure without properly increasing there reference count. I don't really think this is the problem your running into, but you never know :-) Ronald |