On Jul 13, 2014, at 5:24 PM, Daniel Luis dos Santos <[email protected]> wrote:
> On 13 Jul 2014, at 21:10, Kyle Sluder <[email protected]> wrote: > >> On Jul 13, 2014, at 11:24 AM, Daniel Santos <[email protected]> wrote: >>> >>> Hello, >>> >>> I have a collection view in which I have subclassed the collection view >>> item. >>> In the awake from nib method I want to get the represented object but it is >>> returning nil >>> >>> How can I get the bound object ? >> >> You have to wait until after -awakeFromNib. Bindings aren't hooked up and >> propagated until the entire object graph has been awoken. >> >> One option is to override -loadView to call super and then do your magic. > > I just tried that. But [self representedObject] returns nil when called in > the subclassed NSCollectionViewItem. Any idea why ? The collection view creates an item. Then it assigns that item the object it will represent. It can't do that until after the item has been created. That means after -awakeFromNib and after -loadView. The item's representedObject is not an inherent value that it can be expected to have at creation/load time. I don't know what you're trying to achieve. It may make sense to override the setter (-setRepresentedObject:) to have an opportunity to do something when the represented object is assigned to the item. Of course, call through to super. Regards, Ken _______________________________________________ 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]
