Hi all,
I'm trying to implement the searching of a detailView, I have Setlist > Songs > Notes and I'm trying to search through all the Songs in a Setlist to find one Song.
Tarek explained here http://sensiblecocoa...ion/#entry11570 about changing from a regular SCTableViewModel to a SCArrayOfObjectsModel and then setting to TRUE enableSearchController of that SCArrayOfObjectsModel and volia, searching.
Sounded simple. But I'm not getting it to work at all. Here's my stripped back code:
-(void)viewDidLoad { [super viewDidLoad]; self.navigationBarType = SCNavigationBarTypeEditRight; self.managedObjectContext = [(id)[UIApplication sharedApplication].delegate managedObjectContext]; #pragma mark - NoteEntity SCEntityDefinition *noteEntityDefinition = [SCEntityDefinition definitionWithEntityName:@"NoteEntity" managedObjectContext:self.managedObjectContext propertyNamesString:@"noteText" ]; noteEntityDefinition.requireEditingModeToEditPropertyValues = NO; noteEntityDefinition.orderAttributeName = @"noteOrder"; SCPropertyDefinition *noteTextPropertyDefinition = [noteEntityDefinition propertyDefinitionWithName:@"noteText"]; noteTextPropertyDefinition.title = nil; noteTextPropertyDefinition.type = SCPropertyTypeTextView; noteTextPropertyDefinition.existsInCreationMode = YES; noteTextPropertyDefinition.existsInEditingMode = YES; noteTextPropertyDefinition.existsInNormalMode = YES; noteTextPropertyDefinition.existsInDetailMode = YES; noteTextPropertyDefinition.required = YES; #pragma mark - SongEntity SCEntityDefinition *songEntityDefinition = [SCEntityDefinition definitionWithEntityName:@"SongEntity" managedObjectContext:self.managedObjectContext propertyNamesString:@":(songName);:(songNotes);" ]; songEntityDefinition.requireEditingModeToEditPropertyValues = YES; songEntityDefinition.orderAttributeName = @"songOrder"; SCPropertyDefinition *songNamePropertyDefinition = [songEntityDefinition propertyDefinitionWithName:@"songName"]; songNamePropertyDefinition.existsInCreationMode = YES; songNamePropertyDefinition.existsInEditingMode = YES; songNamePropertyDefinition.existsInNormalMode = NO; songNamePropertyDefinition.existsInDetailMode = YES; songNamePropertyDefinition.required = YES; SCPropertyDefinition *notesPropertyDefinition = [songEntityDefinition propertyDefinitionWithName:@"songNotes"]; notesPropertyDefinition.existsInCreationMode = NO; notesPropertyDefinition.existsInEditingMode = YES; notesPropertyDefinition.existsInNormalMode = NO; notesPropertyDefinition.existsInDetailMode = YES; notesPropertyDefinition.required = YES; SCArrayOfObjectsAttributes *notesArrayOfObjectsAttributes = [SCArrayOfObjectsAttributes attributesWithObjectDefinition:noteEntityDefinition allowAddingItems:YES allowDeletingItems:YES allowMovingItems:YES expandContentInCurrentView:YES placeholderuiElement:nil addNewObjectuiElement:[SCTableViewCell cellWithText:@"New Note…" textAlignment:NSTextAlignmentLeft] addNewObjectuiElementExistsInNormalMode:NO addNewObjectuiElementExistsInEditingMode:YES ]; notesArrayOfObjectsAttributes.sectionActions.cellForRowAtIndexPath = ^SCCustomCell*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath) { SCCustomCell *customCell = [SCCustomCell cellWithText:nil objectBindingsString:nil nibName:@"NoteCell"]; return customCell; }; notesPropertyDefinition.attributes = notesArrayOfObjectsAttributes; #pragma mark - SetlistEntity SCEntityDefinition *setlistEntityDefinition = [SCEntityDefinition definitionWithEntityName:@"SetlistEntity" managedObjectContext:self.managedObjectContext propertyNamesString:@":(setlistName);:(setlistSongs);" ]; setlistEntityDefinition.orderAttributeName = @"setlistOrder"; setlistEntityDefinition.requireEditingModeToEditPropertyValues = YES; SCPropertyDefinition *setlistNamePropertyDefinition = [setlistEntityDefinition propertyDefinitionWithName:@"setlistName"]; setlistNamePropertyDefinition.required = YES; setlistNamePropertyDefinition.existsInCreationMode = YES; setlistNamePropertyDefinition.existsInEditingMode = YES; setlistNamePropertyDefinition.existsInNormalMode = NO; setlistNamePropertyDefinition.existsInDetailMode = YES; SCPropertyDefinition *songsPropertyDefinition = [setlistEntityDefinition propertyDefinitionWithName:@"setlistSongs"]; songsPropertyDefinition.existsInCreationMode = NO; songsPropertyDefinition.existsInEditingMode = YES; songsPropertyDefinition.existsInNormalMode = YES; songsPropertyDefinition.existsInDetailMode = YES; SCArrayOfObjectsAttributes *songsArrayOfObjectsAttributes = [SCArrayOfObjectsAttributes attributesWithObjectDefinition:songEntityDefinition allowAddingItems:YES allowDeletingItems:YES allowMovingItems:YES expandContentInCurrentView:YES placeholderuiElement:nil addNewObjectuiElement:[SCTableViewCell cellWithText:@"New Song…" textAlignment:NSTextAlignmentLeft] addNewObjectuiElementExistsInNormalMode:NO addNewObjectuiElementExistsInEditingMode:YES ]; songsArrayOfObjectsAttributes.sectionActions.cellForRowAtIndexPath = ^SCCustomCell*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath) { SCCustomCell *customCell = [SCCustomCell cellWithText:nil objectBindingsString:nil nibName:@"SongCell"]; return customCell; }; songsPropertyDefinition.attributes = songsArrayOfObjectsAttributes; #pragma mark - Setlist Section SCArrayOfObjectsSection *setlistsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil entityDefinition:setlistEntityDefinition]; setlistsSection.addNewItemCell = [SCTableViewCell cellWithText:@"New Setlist…" textAlignment:NSTextAlignmentLeft]; setlistsSection.addNewItemCellExistsInEditingMode = YES; setlistsSection.addNewItemCellExistsInNormalMode = NO; setlistsSection.allowAddingItems = YES; setlistsSection.allowDeletingItems = YES; setlistsSection.allowMovingItems = YES; setlistsSection.allowEditDetailView = YES; setlistsSection.allowRowSelection = YES; setlistsSection.autoSelectNewItemCell = YES; setlistsSection.skipNewItemDetailView = NO; setlistsSection.sectionActions.cellForRowAtIndexPath = ^SCCustomCell*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath) { SCCustomCell *customCell = [SCCustomCell cellWithText:nil objectBindingsString:nil nibName:@"SetlistCell"]; return customCell; }; setlistsSection.sectionActions.detailModelWillPresent = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath) { if (indexPath.row != NSNotFound) { [detailModel logProperties]; } }; [self.tableViewModel addSection:setlistsSection]; }
So that all works as expected. In my detailModelWillPresent the model is a bog standard SCTableViewModel.
If I add in this:
setlistsSection.sectionActions.detailTableViewModelForRowAtIndexPath = ^SCTableViewModel*(SCTableViewSection *section, NSIndexPath *indexPath) { if (indexPath.row == NSNotFound) { return nil; } else { SetlistEntity *setlist = (SetlistEntity *)[section cellAtIndex:indexPath.row].boundObject; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"songSetlist == %@",setlist]; SCArrayOfObjectsModel *arrayOfObjectsModel = [[SCArrayOfObjectsModel alloc] initWithTableView:nil entityDefinition:songEntityDefinition filterPredicate:predicate]; arrayOfObjectsModel.enableSearchController = YES; arrayOfObjectsModel.searchPropertyName = @"songName"; return arrayOfObjectsModel; } };
The model is now indeed a SCArrayOfObjectsModel, and I still get all my Songs in a list, but no search bar. And I now can't re-order the Songs, and I've lost the cell to edit the setlistName.
Very confused!
I'm obviously missing something basic here.
Any pointers very much appreciated.