• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSCollectionView's newItemForRepresentedObject Method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSCollectionView's newItemForRepresentedObject Method


  • Subject: NSCollectionView's newItemForRepresentedObject Method
  • From: "Carter R. Harrison" <email@hidden>
  • Date: Sun, 3 Feb 2008 08:14:39 -0500

There was some discussion on NSCollectionView's newItemForRepresentedObject method earlier on the list, but it didn't quite cover what I was looking for. Hopefully you all can help. To make a long story short, I'm trying to figure out how to modify the size of each view as it is added to an NSCollectionView. Read on for details.

I built my NSCollectionView in Interface Builder and this of course built an NSView and NSCollectionViewItem prototype in IB as well with all the connections already hooked up for me.

Now I want to subclass NSCollectionView so that I can override the newItemForRepresentedObject method. My intention is to modify the frame of each object's individual view as it is added to the NSCollectionView. This requires me to look at some of the subviews within the view itself - which at this point are just Interface Builder outlets since my view was built in IB.

When the newItemForRepresentedObject method runs, I have verified that I can get a reference to each view as it is created, but using the view's IB outlets to get to the various subviews doesn't seem to work. See code below...

- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object
{
NSCollectionViewItem *newItem = [super newItemForRepresentedObject:object];
CHMessageView *newView = (CHMessageView *)[newItem view];
//Next line of code for some reason returns nil.
CHMessageTextView *newTextView = [newView messageTextView];
//More code here that is not relevant.
return newItem;
}


So my next thought was to actually create my view programmatically rather than through IB. Sorta like this - the problem here is that I don't know what to put for the view's frame in the initWithFrame method.

- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object
{
NSCollectionViewItem *newItem = [super newItemForRepresentedObject:object];
//What do I use for the new view's frame?
CHMessageView *newView = [[CHMessageView alloc] initWithFrame:NSMakeRect(?, ?, ?, ?)];
CHMessageTextView *newTextView = [newView messageTextView];
[newItem setView: newView];
return newItem;
}


So hopefully that wasn't too confusing, but my main question is - how do I modify the size of each subview as it is added to the NSCollectionView? Thanks everybody. This list has been so helpful.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSCollectionView's newItemForRepresentedObject Method
      • From: Gernot <email@hidden>
  • Prev by Date: Re: Programmatically connecting outlets
  • Next by Date: Re: NSCollectionView's newItemForRepresentedObject Method
  • Previous by thread: Re: Programmatically connecting outlets
  • Next by thread: Re: NSCollectionView's newItemForRepresentedObject Method
  • Index(es):
    • Date
    • Thread