0

Maybe I'm stupid but I spent the whole afternoon trying to figure out this one. I'm an Objective C novice, but have plenty experience in other languages.

I have two NSCollectionView - *eventsView and *projectsView inside a menu. Each with its own itemPrototype which are two subclasses of NSCollectionViewItem both with their own .xib files.

The problem is that it's always the first .xib file that loads - for both NSCollectionViewItem. So projectsView doesn't load its own .xib but it loads the eventsView one. The funny thing is if I delete that .xib, both load the second .xib which no one loaded before.

I've run out of keywords to search for on Google, so here I am.

The code (though I don't know it matters) is:

NSMenuItem *events = [[NSMenuItem alloc] init];
self.eventsView = [[NSCollectionView alloc] initWithFrame:NSZeroRect];
HeadquartersEventsViewItem *eventsPrototype = [[HeadquartersEventsViewItem alloc] init];
[self.eventsView setItemPrototype:eventsPrototype];
[events setView:self.eventsView];
[self.menu addItem:events];

[self fetchEvents];

[self.menu addItem:[NSMenuItem separatorItem]];

NSMenuItem *projects = [[NSMenuItem alloc] init];
self.projectsView = [[NSCollectionView alloc] initWithFrame:NSZeroRect];
HeadquartersProjectsViewItem *projectsPrototype = [[HeadquartersProjectsViewItem alloc] init];
[self.projectsView setItemPrototype:projectsPrototype];
[projects setView:self.projectsView];
[self.menu addItem:projects];

[self fetchProjects];

Where is the catch? Why does Xcode not differentiate between those 2 .xibs?

Miha Rekar
  • 1,237
  • 12
  • 15
  • What is the file owner of every xib file? – Ramy Al Zuhouri Dec 22 '12 at 17:29
  • @AnoopVaidya tried many times - same. – Miha Rekar Dec 22 '12 at 17:31
  • @RamyAlZuhouri the way it should be (I guess) - `HeadquartersEventsViewItem` in the HeadquartersEventsViewItem.xib and `HeadquartersProjectsViewItem` in the HeadquartersProjectsViewItem.xib – Miha Rekar Dec 22 '12 at 17:33
  • Maybe the binding are wrong and you bound both collection views to the same xib.Try to delete the other xib (the one that gets loaded), and see what happens. – Ramy Al Zuhouri Dec 22 '12 at 17:35
  • These are XIB with windowControllers or only View with viewControllers? And how you are init & loading these xib's? – Anoop Vaidya Dec 22 '12 at 17:35
  • @RamyAlZuhouri I already wrote in the original post. If i delete one, both load the other one :D – Miha Rekar Dec 22 '12 at 17:40
  • must be wrong bindings in interface builder. – manitu Dec 22 '12 at 17:41
  • @AnoopVaidya XIB with viewcontrollers. I created all of them via creating new NSCollectionViewItem subclass and checking the "With XIB for UI". The above is all the code I have regarding this. I thought Xcode loads all of that automagically. – Miha Rekar Dec 22 '12 at 17:42
  • @kitschmaster what bindings? I have views set on file owners and each file owner has the right class name. – Miha Rekar Dec 22 '12 at 18:26
  • What xibs are you talking about? I don't see anything in your posted code that explicitly loads a particular xib file. Shouldn't you be using initWithNibName:bundle: to initialize your collection view item? – rdelmar Dec 22 '12 at 23:56

0 Answers0