André's Blog

PHP, Zend Framework, Mac/Cocoa Programming

NSCollectionView Tutorial for Dummies (Xcode 3.1.3)

with 48 comments

Note: I wrote this tutorial since I believe that there are way too few resources on the net covering this topic and I would have been wasting way less time if I had found something like this. Please keep in mind that I’m a ObjC-beginner myself.

Introduction

This tutorial is written in a way that it doesn’t require much knowledge of cocoa/objective-c, but since I’m not explaining most of the code, programming experiences will be helpful to understand what you are doing.

The following things will be covered by this tutorial:

  • designing a user interface with buttons and a NSCollectionView
  • designing a Subview which should be displayed in the CollectionView
  • feeding the CollectionView using an ArrayController
  • making the items in the CollectionView selectable

This is what the final application at the end of the tutorial will look like:

NSCollectionView Tut Step 13

Getting Started

Let’s start off by creating a fresh project and opening up the MainMenu.nib. Next drag a Collection View from the Library to the main view. It can be found under Library->Cocoa->Views & Cells->Data Views->Collection View.

Do the same with 2 buttons which you can get from Library->Cocoa->Views & Cells->Buttons. Give them a label(“add” and “remove”) by clicking them twice.

Your window should now look similar to this:

NSCollectionView Tut Step 1

Also we’ll be needing a Window Controller: To add it go to Library->Cocoa->Objects & Controllers->Controllers and drag an Object into the Document Window. While having it selected in the Document Window, go to the Identity tab of the Inspector and change the class name to something like “WindowController”.


NSCollectionView Tut Step 2

Keep it selected and go to File->Write Class Files, accept to save the “WindowController.m” and to create a “WindowController.h”. Now you should be able to see those 2 files in Xcode. Open up the “WindowController.h” which should look like this:

#import < Cocoa /Cocoa.h>

@interface WindowController : /* Specify a superclass (eg: NSObject or NSView) */ {

}

@end

As you can see we’ll have to specify the superclass of our WindowController to do this replace the comment with NSWindowController, save and in the Interface Builder select File->Reload All Class Files.

Setting Up The Bindings

NSCollectionView Tut Step 3Now that we’re done with the basic interface, let’s connect the controls to our WindowController.

To do this select the WindowController and open the Identity tab in the Inspector.

Here add two class actions(addAction and removeAction) and one class outlet collectionView of the type NSCollectionView as seen on the left.

Finally, go to File->Write Class File and merge the changes.

Our WindowController should now look like this:

WindowController.h

#import < Cocoa /Cocoa.h>

@interface WindowController : NSWindowController {
    IBOutlet NSCollectionView *collectionView;
}
- (IBAction)addAction:(id)sender;
- (IBAction)removeAction:(id)sender;
@end

WindowController.m

#import "WindowController.h"

@implementation WindowController
- (IBAction)addAction:(id)sender {

}

- (IBAction)removeAction:(id)sender {

}
@end

Go back to the Interface Builder and hold the Ctrl-key while “drawing” a line from the add button to the WindowController(in the Document Window).
NSCollectionView Tut Step 4
Release the mouse over the WindowController and select “addAction”. The function addAction is now being called whenever the add button is clicked. Repeat this for the remove button and its corresponding removeAction.

Now we’ll be doing the same just the other way around: Draw a line from the WindowController to the CollectionView and select “collectionView”. Do the same with the background of the window and connect it to “window”. This will make both the window and the CollectionView accessible from our WindowController.

If you would like to see what connections have been made you could right-click for example on the WindowController and should see this:

NSCollectionView Tut Step 5

Designing the NSCollectionViewItem

Next up, we would like to design the interface of an item in our CollectionView. Therefore, go to Xcode and select File->New File->View XIB, name it however you like(f.e. collectionItem) and open it up in Interface Builder.

Make the View a little bit smaller – I chose 150×150(you can set that in the Size tab of the Inspector).

Drag a Label(Library->Cocoa->Views & Cells->Inputs & Values) and a Segmented Control(same place as the Label) onto the view. Change the text of the label to “Joe”, change the number of segments of the Segmented Control(Attributes tab of the Inspector) to ‘2’ and change their labels to “male” and “female”. This it what you should have got:

NSCollectionView Tut Step 6

Setting Up the Bindings of the CollectionViewItem

First change the Class Identity of the File’s Owner(in the Document Window) to “CollectionItem”(in the Identity tab of the Inspector). At the same place add a Class Action “updateGender” and two Class Outlets gender(NSSegmentedControl) and name(NSTextField):

NSCollectionView Tut Step 7

Now you should go to File->Write Class Files. In the “CollectionViewItem.h” you’ll have to specify the superclass of the CollectionItem(remember the WindowController.h?) . This time we want to extend NSCollectionViewItem so you need to put that there instead of the comment:

CollectionItem.h

#import < Cocoa /Cocoa.h>

@interface CollectionItem : NSCollectionViewItem {
    IBOutlet NSSegmentedControl *gender;
    IBOutlet NSTextField *name;
}
- (IBAction)updateGender:(id)sender;
@end

CollectionItem.m

#import "CollectionItem.h"

@implementation CollectionItem
- (IBAction)updateGender:(id)sender {

}
@end

Now all that’s left for us to do in this view is to connect File’s owner with the text field(name) and with the seg-control(gender), the seg-control with the File’s owner(updateGender) and finally the File’s owner with the view itself(view – click in the background).

NSCollectionView Tut Step 8

Make the CollectionItem load its Interface

Everytime we add a new CollectionItem to the CollectionView a new subinterface has to be loaded(the collectionItem.xib). To do this we’ll have to add the copyWithZone method to our CollectionItem:

CollectionItem.h

#import < Cocoa /Cocoa.h>

@interface CollectionItem : NSCollectionViewItem {
    IBOutlet NSSegmentedControl *gender;
    IBOutlet NSTextField *name;
}
- (IBAction)updateGender:(id)sender;
- (id)copyWithZone:(NSZone *)zone;
@end

CollectionItem.m

#import "CollectionItem.h"

@implementation CollectionItem
- (IBAction)updateGender:(id)sender {

}

-(id)copyWithZone:(NSZone *)zone
{
	id result = [super copyWithZone:zone];

	[NSBundle loadNibNamed:@"collectionItem" owner:result];

	return result;
}
@end

Where @”collectionItem” refers to the name of the “collectionItem.xib”.

Adding an ArrayController

To be able to feed the CollectionView with items we’ll need to add an ArrayController.
To do that go to our MainMenu.xib in Interface Builder and drag an ArrayController(Library->Cocoa->Objects & Controllers->Controllers) to the Document Window.

This might also be a good moment to change the Class Identity of the Collection View Item(which has been automatically created when we added the NSCollectionView)  from NSCollectionViewItem to “CollectionItem”.

In Xcode open the WindowController.h and add the outlet arrayController, the mutableArray collection and the property collection:

WindowController.h

#import < Cocoa /Cocoa.h>

@interface WindowController : NSWindowController {
    IBOutlet NSCollectionView *collectionView;
	IBOutlet NSArrayController *arrayController;

	NSMutableArray* collection;
}
- (IBAction)addAction:(id)sender;
- (IBAction)removeAction:(id)sender;

- (void) awakeFromNib;

@property (copy) NSArray* collection;

@end

In the CollectionItem.m the method awakeFromNib needs to implemented and a synthesize statement needs to be added:

WindowController.m

#import "WindowController.h"

@implementation WindowController

@synthesize collection;

- (IBAction)addAction:(id)sender {

}

- (IBAction)removeAction:(id)sender {

}

- (void) awakeFromNib {

	collection = [[NSMutableArray alloc] init];
	NSSize size = NSMakeSize(150, 150);
	[collectionView setMinItemSize:size];
	[collectionView setMaxItemSize:size];
}

@end

Save and switch to the Interface Builder where you should reload the class files(File->Reload All Class Files).
Select the ArrayController and in the Bindings Pane of the Inspector and under “Content Array” set “Bind to:” to “Window Controller” and the “Model Key Path” to controller(as we named the property earlier).
NSCollectionView Tut Step 9

Hold Ctrl and draw a line from the WindowController to the ArrayController and bind it to “arrayController”.
We’re almost done all that’s left to do is to connect the CollectionView to the Array:
Click on the CollectionView multiple times and make sure it really is the CollectionView and not the ScrollView surrounding it. Go to the Bindings tab and bind “Content” to the ArrayController with arrangedObjects as the “Controller Key”. Also bind “Selection Indexes” to the ArrayController with the “Controller Key” set to “selectionIndexes”.
NSCollectionView Tut Step 10

Finally: Adding items to the CollectionView

The time has come to implement the addAction in the WindowController and take our application for a test run.

Open up the WindowController.m in Xcode and copy over the body of the addAction method:

- (IBAction)addAction:(id)sender {
	int index = [[arrayController arrayController ">arrangedObjects] count];
	[arrayController insertObject: [NSDictionary dictionaryWithObjectsAndKeys:@"Jon", @"Name", @"Male", @"Gender",nil] atArrangedObjectIndex:index];
}

- (IBAction)removeAction:(id)sender {
 	int index = [[arrayController arrangedObjects] count];
	if ( index > 0) {
		index--;
		[arrayController removeObjectAtArrangedObjectIndex:index];
	}
}

Now you can finally start and play with it. Even though it doesn’t do much yet, I hope you can already see how much potential and how many use cases the CollectionView actually has. At least that’s what I thought when I played around with it for the first time.

Just for you to check if you did everything the way I described it(at least how I tried to):

NSCollectionView Tut Step 11

Enuf with the Joes

Now we want to have other names than Joe.

We’ll start by adding a new class(File->New File->Objective-C class) and name it “Person.m”:

Person.h

#import < Cocoa /Cocoa.h>

@interface Person : NSObject {

}

+ (NSString*)getRandomMaleName;
+ (NSString*)getRandomFemaleName;
+ (NSString*)getRandomGender;

@end

Person.m

#import "Person.h"
#include < stdlib .h>

@implementation Person

+ (NSString*)getRandomMaleName {
	NSMutableArray *names = [NSMutableArray NSMutableArray ">arrayWithObjects:@"Jon", @"Steve", @"Benjamin", @"Chris", @"Andre", @"Tom", @"Paul", @"Peter", @"Ron", @"Robert", @"Matthew", @"Max", @"Alex", @"Sebastian", nil];

	int randIndex = arc4random() % [names count];
	return [names objectAtIndex:randIndex];
}

+ (NSString*)getRandomFemaleName {
	NSMutableArray *names = [NSMutableArray arrayWithObjects:@"Abbey", @"Alice", @"Cindy", @"Chrissy", @"Gina", @"Hannah", @"Lena", @"Lilli", @"Linda", @"Monica", @"Nadine", @"Nancy", @"Theresa", @"Tiffany", nil];

	int randIndex = arc4random() % [names count];
	return [names objectAtIndex:randIndex];
}

+ (NSString*)getRandomGender {
	NSMutableArray *genders = [NSMutableArray arrayWithObjects:@"male", @"female", nil];

	int randIndex = arc4random() % [genders count];
	return [genders objectAtIndex:randIndex];
}

@end

The class Person offers 3 static methods:

  • getRandomMaleName: randomly returns a male’s first name
  • getRandomFemaleName: randomly returns a female’s first name
  • getRandomGender: randomly returns either @”male” or @”female”

Now we can slightly modify the addAction in the WindowController.m to generate a random name for a random gender when adding the item:

Add the following line at the top of the file:

#import "Person.h"

Add copy over the body of the addAction method:

- (IBAction)addAction:(id)sender {
	int index = [[arrayController arrayController ">arrangedObjects] count];
	NSString *gender = [Person getRandomGender];
	NSString *name;

	if ([gender isEqualToString:@"male"]) {
		name = [Person getRandomMaleName];
	} else {
		name = [Person getRandomFemaleName];
	}

	[arrayController	insertObject: [NSDictionary dictionaryWithObjectsAndKeys:
										name,		@"Name",
										gender,		@"Gender",
										nil]
						atArrangedObjectIndex:index];
}

But our CollectionItem doesn’t use the supplied informations yet, so we’ll add the method setRepresentedObject in CollectionItem. Also we’ll implement the updateGender method which gets called whenever you click on the segmented control:

CollectionItem.h

#import < Cocoa/ Cocoa.h>

@interface CollectionItem : NSCollectionViewItem {
    IBOutlet NSSegmentedControl *gender;
    IBOutlet NSTextField *name;
}
- (IBAction)updateGender:(id)sender;
- (id)copyWithZone:(NSZone *)zone;
- (void)setRepresentedObject:(id)object;

@end

CollectionItem.h

#import "CollectionItem.h"
#import "Person.h"

@implementation CollectionItem
- (IBAction)updateGender:(id)sender {
	NSString *newName;
    switch ([gender	selectedSegment]) {
		case 0:
			NSString ">newName = [Person getRandomMaleName];
			break;
		default:
			newName = [Person getRandomFemaleName];
			break;
	}

	[name setStringValue:newName];
}

-(id)copyWithZone:(NSZone *)zone
{
	id result = [super copyWithZone:zone];

	[NSBundle loadNibNamed:@"collectionItem" owner:result];

	return result;
}

- (void)setRepresentedObject:(id)object {
	[super setRepresentedObject:	object];

	if (object == nil)
		return;

	NSDictionary* data	= (NSDictionary*) [self representedObject];
	NSString* newName	= (NSString*)[data valueForKey:@"Name"];
	NSString* newGender	= (NSString*)[data valueForKey:@"Gender"];

	[name setStringValue:newName];

	if ([newGender isEqualToString:@"male"]) {
		[gender setSelectedSegment:0];
	} else {
		[gender setSelectedSegment:1];
	}
}

@end

You can now compile & run the application.

NSCollectionView Tut Step 12

Making the Items Selectable

To make the items selectable open the main interface(mainMenu.xib) in Interface Builder and while having the CollectionView selected go to the Attributes tab and enable “Selectable”.

Now our items are selectable, but we don’t see when they are yet. We’ll have to change the background color when an item is being selected.

Here’s how:  Open the collectionItem.xib and select the View in the Document Window. Change its Class Identity(Identity tab) to NSBox.

Next add those two functions to the CollectionItem.m:

- (void)setSelected:(BOOL)flag {
	[super setSelected:	flag];

	NSBox *view	= (NSBox*) [self view];
	NSColor *color;
	NSColor *lineColor;

	if (flag) {
		color		= [NSColor selectedControlColor];
		lineColor	= [NSColor blackColor];
	} else {
		color		= [NSColor controlBackgroundColor];
		lineColor	= [NSColor controlBackgroundColor];
	}

	[view setBorderColor:lineColor];
	[view setFillColor:color];
}

- (void) awakeFromNib {
	NSBox *view	= (NSBox*) [self view];
	[view setTitlePosition:NSNoTitle];
	[view setBoxType:NSBoxCustom];
	[view setCornerRadius:8.0];
	[view setBorderType:NSLineBorder];
}

That’s it!
NSCollectionView Tut Step 13
BTW: You can also use the arrow keys.

Conclusion

That’s all I wanted to show in this tutorial. I hope you enjoyed it, even though the final app doesn’t do anything useful. It’s main purpose was to show how the NSCollectionView works and what can be done with it. The cool thing about the CollectionView is that you can dynamically create a set of views that can be customized for its purpose and create a nice user experience.

The final source code can be downloaded here.

One last thing: If you want to know what item is currently selected use [collectionView selectionIndexes] which returns a NSIndexSet.

Feel free to leave suggestions or the like in the comments.

Written by andrehoffmann

August 29, 2009 at 7:29 pm

48 Responses

Subscribe to comments with RSS.

  1. […] post: NSCollectionView Tutorial for Dummies (Xcode 3.1.3) « André's Blog Share and […]

    • This project of collectionview can not run on 10.6.version goes into infinite loop
      Can you please send me the correct code

      Swapnil Sherekar

      January 13, 2012 at 1:48 pm

  2. Thank you for writing this tutorial. It’s interesting, but I can’t finish it. First, I’m on 3.2 now, so some of this no longer applies. For example, adding actions and outlets is now on the classes tab of the library. And the loadNibNamed method seems to be gone from NSBundle.

    The section Adding an ArrayController is confusing. What do you mean by main interface? Do you mean the original MainMenu xib?

    “To be able to feed the CollectionView with items we’ll need to add an ArrayController.
    To do that go to our main interface in Interface Builder and drag an ArrayController(Library->Cocoa->Objects & Controllers->Controllers) to the Document Window.”

    Also, this is confusing:

    “This might also be a good moment to change the Class Identity of the Collection View Controller(which has been automatically created when we added the NSCollectionView) to “CollectionItem”.”

    I don’t seem to have a Collection View Controller in either Xib.

    Thank you again.

    Mike

    September 1, 2009 at 4:45 pm

    • Hi Mike,
      sorry for the delay – wordpress marked you as spam 🙂

      And the loadNibNamed method seems to be gone from NSBundle.

      Can’t test that right now, but it doesn’t say anything about loadNibNamed being obsolete on this site.

      What do you mean by main interface? Do you mean the original MainMenu xib?

      Yes I mean the MainMenu.xib.

      I don’t seem to have a Collection View Controller in either Xib.

      I apologize for having confused things there. To clarify: When you create a new NSCollectionView in the Interface Builder a NSCollectionViewItem named Collection View Item will be created automatically. The class name of this object is what you’ll need to modify.

      Also did you try downloading the final source code at the bottom of the page?

      Hope that helps, If not let me know.

      Thanks for your feedback!

      andrehoffmann

      September 4, 2009 at 10:34 pm

      • Apparently this should be

        [NSBundle loadNibNamed:@”collectionitem” owner:result];

        (remove the option:nil)

        guillaume

        September 9, 2009 at 1:03 pm

      • Yes you are right – I changed it.

        Thanks for the feedback.

        andrehoffmann

        September 9, 2009 at 1:17 pm

  3. This site rocks!

    Bill Bartmann

    September 6, 2009 at 8:14 pm

  4. Great site…keep up the good work.

    Bill Bartmann Scam?

    September 8, 2009 at 6:35 pm

  5. Hi,

    Nice tutorial and well explained, it works well on 10.5, but does not work at all on 10.6. Perhaps NSCollectionView has gone some modifications. Do you have an idea on how to have this working?

    Thanks!

    Guillaume

    September 11, 2009 at 12:43 am

    • Yes, I know that there have been quite a few changes to NSCollectionView in Mac OS X 10.6, but those shouldn’t be very significant for this tutorial as far as I know.

      Maybe you can tell me where you get stuck?

      Unfortunately I can’t test it as my Snow Leopard license still didn’t arrive(I ordered it on Amazon, but they and every other reseller seem to have problems delivering it, which kinda sucks).

      andrehoffmann

      September 11, 2009 at 2:15 am

      • With the downloaded example project, it does not launch but rather tells an infinite number of time in the console:

        NSCollectionViewTest[363:a0f] Could not connect the action buttonPressed: to target of class CollectionItem

        Guillaume

        September 11, 2009 at 2:19 pm

      • I was just wondering if you have had a chance to run this tutorial with snow leopard. I have tried but had not success in understanding what was going wrong. Thanks!

        Guillaume

        November 12, 2009 at 8:22 pm

    • I actually did not have the time to reproduce this on 10.6, but you might want to have a look at my question on stackoverflow which pretty much explains how to do it on 10.6: http://stackoverflow.com/questions/1484263/nscollectionview-in-10-6-xcode-3-2

      andrehoffmann

      November 23, 2009 at 10:02 am

  6. Based on this example, I’m trying to implement something that should be simple but so far, I have failed.

    I would like to have a button to the main view that will change the name of the first item. I choose the first one for simplicity.

    I guess I can change his name by writing this method in WindowController.m

    – (IBAction)changeName:(id)sender {

    [[[arrayController arrangedObjects] objectAtIndex:0] setValue:@”New Name” forKey:@”Name”];

    }

    But I don’t know how to ask the CollectionItem to display the change. I have tried by asking the NSCollectionView to redisplay itself, but nothing happens. I have also tried to select the view at index 0 but was not more successful.

    Do you have any advice? Thanks!

    guillaume

    September 11, 2009 at 6:21 pm

    • I found how to do this in a very inelegant way: removing an item and creating a new one:

      [arrayController removeObjectAtArrangedObjectIndex:0];
      [arrayController insertObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:
      @”hop”, @”Name”,
      nil]
      atArrangedObjectIndex:0];

      But I guess there must be a way to update a view without deletion and insertion.

      guillaume

      September 12, 2009 at 12:57 am

      • Have you tried calling rearrangeObjects after editing(not inserting/removing) the representedObject?

        Also try to add a NSLog statement in setRepresentedObject to see if it gets called.

        andrehoffmann

        September 12, 2009 at 1:17 am

  7. Thank you for a good piece of work. I have been struggling to pick up IB and this tutorial was very helpful.
    Jack

    Jack

    November 23, 2009 at 3:24 am

  8. your sample code is not running in Snow Leopard it is giving this error: Could not connect the action buttonPressed: to target of class CollectionItem

    miraaj

    January 22, 2010 at 2:30 pm

  9. Great tutorial, any idea how to implement drag and drop for NSCollectionView, am not able to get any help from google.
    Drag works but no callbacks on drop :(.

    Alex

    April 10, 2010 at 1:59 am

    • I will have a look at it tomorrow.

      If I find something helpful I’ll let you know.

      andrehoffmann

      April 10, 2010 at 8:24 pm

  10. One thing, in the section labeled:

    “Finally: Adding items to the CollectionView”

    there’s a line of code that looks like this

    int index = [[arrayController arrayController “>arrangedObjects] count];

    That can’t possibly be correct looking at the zip file that line looks like this

    int index = [[arrayController arrangedObjects] count];

    Which makes a lot more sense. Perhaps you want to update the code in the blog as I’m sure some people, like me, are working through it while reading the blog.

    Tony Giaccone

    April 10, 2010 at 7:31 pm

    • Odd, it show up correctly in Safari.

      No idea what went wrong there. This wordpress plugin is a pita, but since I don’t host it myself I can’t change it.

      andrehoffmann

      April 10, 2010 at 8:28 pm

  11. Just a question: has someone been able to have this tutorial running on 10.6?

    This is the best tutorial on the web for NSCollectionView, but I have not been able to have it run on 10.6.

    Guillaume

    April 10, 2010 at 7:35 pm

  12. It does run on my installation of Snow Leopard just fine – I made no changes whatsoever. Also, I did spend a couple of days after OS installation migrating all my ports and other libraries to 64 bit, so may be that’s the thing – the migration has solved *a lot* of issues I was having with various dev tools after upgrading to 10.6 from 10.5.

    An issue that I’m having is that there’s doesn’t seem to be a ‘Class Action’ option in the Identity tab of the Inspector anymore. I have buttons in my view items that I cannot find a way to connect to, well, anything. Is it even possible or is this purely for displaying the data?

    Thanks,
    A.T.

    A.T.

    April 15, 2010 at 4:52 am

  13. More like “NSCollectioView Tutorial for Pro users”. Maybe it’s me, most steps are hard to follow and I couldn’t go through step 4 or 5.

    Alan

    June 12, 2010 at 5:23 pm

  14. How can I cancel the item of selected?
    In this example, it’s cancel the last item.
    Thx a lot!

    Johnny

    January 14, 2011 at 10:38 am

  15. Is there a missing step where you assign nib file to the Collection View Item in the Document Window. With out that assignment the code [super copyWithZone:zone] exits with error.

    milen milkovski

    March 17, 2011 at 11:28 pm

  16. Hmm when i try to run the project the log just throws
    NSCollectionViewTest[1379:c03] Could not connect the action buttonPressed: to target of class CollectionItem
    But everthing is connected as it should.
    Iam using XCode 4.2 and Lion 7.2

    Freddy

    October 19, 2011 at 3:55 pm

    • this is happening to me also, its driving me crazy !!

      Hope someone finds the solution!

      Estin

      October 23, 2011 at 7:20 pm

    • Here’s the solution.

      1. Open “MainMenu.xib”.
      2. Select “Collection Item”
      3. From Attributes inspector, add Nib Name as “collectionItem”
      4. Done

      Additionally, copyWithZone implementation is not needed anymore.

      Seongyoon

      March 28, 2012 at 6:32 pm

      • thank you… below code is not working…

        -(id)copyWithZone:(NSZone *)zone
        {
        id result = [super copyWithZone:zone];

        [NSBundle loadNibNamed:@”collectionItem” owner:result];

        return result;
        }

        muruganandham

        May 6, 2013 at 6:40 am

  17. This tutorial is awesome! Thanks so much!

    Rem.co

    October 1, 2012 at 9:42 pm

  18. if I want to highlight the box programmatically, can I call setSelected directly and modify the flag variable to YES??

    Yu Feng

    November 12, 2013 at 9:14 pm

    • yes you can (unless you want to use bindings for this operation)

      jaskhgksgfghg

      November 14, 2013 at 6:03 am

  19. This post is still awesome and works on 10.9. I recommend pitting the collectionViewItem nib name against the CollectionViewItem object definition in the main NIB and commenting out the copyWithZone.

    So I’ve spent most of the evening fighting with the NIB not having loaded… and solved that with the above. The next challenge is that I’m displaying 27 images… and not all of them show on the screen at once… so when I scroll my collectionView … the next set of collectionViewItems are blank or empty … so something isn’t happening if they are not shown on the screen and something isn’t happening when they scroll into view… this will become tomorrow evenings investigation…

    Again, great post.

    David Wilson

    November 25, 2013 at 12:08 pm

  20. Hi, thanks for the post. Still worth reading when trying to make application running even on old OSX releases. I have compiled with Xcode 3.2.1, but get this is loop :
    2014-06-06 00:31:12.938 NSCollectionViewTest[74296:a0f] Could not connect the action buttonPressed: to target of class CollectionItem
    2014-06-06 00:31:12.943 NSCollectionViewTest[74296:a0f] Could not connect the action buttonPressed: to target of class CollectionItem
    2014-06-06 00:31:12.945 NSCollectionViewTest[74296:a0f] Could not connect the action buttonPressed: to target of class CollectionItem

    What could be done ?
    Thanks

    fred

    June 6, 2014 at 12:34 am

  21. fantastic coding

    Sasi

    March 12, 2015 at 9:46 am

  22. Great Tutorial

    jin

    June 23, 2015 at 4:47 am

  23. But I am using Xcode 6.3.2 now 🙂

    jin

    June 23, 2015 at 4:49 am

  24. you need to use : id result = [[[self class] alloc] init]; else it will crash in copywithzone.

  25. has anyone implemented [collectionView selectionIndexes], i am not able to achieve it.

  26. https://vietuniversity.com/reilobase dervienn nerissa c94ff34b83

    dervienn

    December 14, 2021 at 12:16 pm

  27. http://www.bdsm-sm.com/danthcilsimpco glengabri waldon 4b1f4b8a67

    glengabri

    December 16, 2021 at 3:30 am


Leave a reply to Guillaume Cancel reply