1
votes

I am trying to create a nested collection view. First I did for one level.

Created a data model class with String header. In app delegate created an array sectionTitle. Now in the nib, I added collection view & array controller and did all the bindings following this guide. Next in awakeFromNib I populated some random data

- (void)awakeFromNib {
    int idx = 0;
    NSMutableArray *sectionTitle = [[NSMutableArray alloc] init];
    while (idx < 1) {
        HeaderModel *header = [[HeaderModel alloc] init];
        [header setHeader:[NSString stringWithFormat:@"Section %d", idx]];
        [sectionTitle addObject:header];
        idx++;
    }
    [self setHeaderData:sectionTitle];
}

Running it will give me 4 sections. I want to achieve similar layout as this. Section title, under it another collection of items. The answer given there only hints at using Nested collection view.

So I added another collection view in the first view prototype. Then I followed the same approach what I did for the first view(with different data model and array).

- (void)awakeFromNib {
    int idx = 0;
    NSMutableArray *sectionTitle = [[NSMutableArray alloc] init];
    NSMutableArray *groupData = [[NSMutableArray alloc] init];
    while (idx < 1) {
        HeaderModel *header = [[HeaderModel alloc] init];
        DataModel *name = [[DataModel alloc] init];
        [header setHeader:[NSString stringWithFormat:@"Section %d", idx]];
        [name setName:[NSString stringWithFormat:@"Name %d", idx]];
        [sectionTitle addObject:header];
        [groupData addObject:name];
        idx++;
    }
    [self setHeaderData:sectionTitle];
    [self setData:groupData]; //NSCollectionView item prototype must not be nil.
}

But now I get the error NSCollectionView item prototype must not be nil. How do I resolve this ?

1
Any luck resolving this?tofutim

1 Answers

1
votes

I have just answered a similar question here

But somehow by inserting the second NSCollectionView with I.B, you get a corrupted prototype for your inner NSCollectionViewItem. Simply try to extract each associated NSView into its own .xib