Question

I have the following core data setup.

Data Setup

I have created an array controller called "SongsInMedleys" which is configured to contain the content of the SongsInMedleys with a specific medleyid.

I have created a view based Tableview which are bind to the SongsInMedleys array controller.

That is working fine, and I have managed to get the set the song title in a label by binding to Table Cell View and using objectValue.withSongs.title in the Model Key Path.

Now to my issue:

I would like to create a collection view inside the Table Cell View with all the verses to the related song. (objectValue.withSongs.withVerses)

Any suggestion to how I can do that???

Model of what I am trying to create : Model

Was it helpful?

Solution

After some research I gave up try adding a collection view inside the tableview. Insted I added my verses manually in the subclass of the NSTableCellView

-(void) setObjectValue:(id)objectValue {

    if (objectValue != nil)
    {
    [super setObjectValue:objectValue];

    SongsInMedleys *Sim = objectValue;
    Songs *song = Sim.withSongs;

    scrollView *scrollview = [[scrollView alloc] initWithFrame:NSMakeRect(10,5,[self frame].size.width-30,145)];

    int addverses = 0;

    for (VersesInSongs *verse in song.withVerses)
    {
        if ([verse.lyric length] > 0) {
            addverses += 1;
        }

    }

    NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(5, 10, ((addverses * (169+5))+5), 140)];


    int x = 5;

    NSSet *Verses = song.withVerses;
    NSSortDescriptor *sortVerses = [[NSSortDescriptor alloc] initWithKey:@"number" ascending:YES];
    NSArray *sortedVerses = [Verses sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortVerses]];

    for (VersesInSongs *verse in sortedVerses)
    {
         if ([verse.lyric length] > 0) {
             verseBox *box = [[verseBox alloc] initWithFrame:NSMakeRect(x, 10, 169, 130)];

             [box setSong:song];
             [box setVerse:verse];
             [view addSubview:box];

             x = x + 169+5;
         }

    }
    [scrollview setDocumentView:view];
    [self addSubview:scrollview];
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top