Welcome, Guest
Username Password: Remember me

autoGeneratePropertyDefinitions not building second level relationship
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: autoGeneratePropertyDefinitions not building second level relationship

autoGeneratePropertyDefinition​s not building second level relationship 1 year, 4 months ago #1

I am using STV to present UI for detail view off of a custom tableview using custom cells defined in xib files. I plan to try out the beta to replace this tableview but I am curious as to what I am doing wrong before I move on.

My model is simply
CheckListItem [has a] CheckListItemGroup [has a] CheckList

When I use the following code, the CheckListItem detail view is beautiful and works perfectly. I can follow the relationship from CheckListItem to CheckListItemGroup. I can update the CheckListItemGroup title attribute but the relationship from CheckListItemGroup to CheckList does not present a lookup row to select and/or modify the CheckList.

How do I tell STV to autogenerate the properties on the entities resulting from walking the relationships?

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// get the checklist item for index path
CheckListItem *item = (CheckListItem *)[self.fetchedResultsController objectAtIndexPath:indexPath];
 
// create a generic UITableViewController to use for detail view
[self setDetailViewController:[[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped ]];
 
// create a table view model for sensible tableview
[self setDetailViewModel:[SCTableViewModel tableViewModelWithTableView:[self detailViewController].tableView
withViewController:[self detailViewController]]];
 
 
// Create a class definition for CheckListItem
SCClassDefinition *scClassDef = [SCClassDefinition definitionWithEntityName:@"CheckListItem"
withManagedObjectContext:[self managedObjectContext]
autoGeneratePropertyDefinitions:YES];
 
// Create an SCObjectSection for the detail model
SCObjectSection *objectSection = [SCObjectSection sectionWithHeaderTitle:nil
withBoundObject:item
withClassDefinition:scClassDef];
 
// add the section to the tableview controller's table model
[[self detailViewModel] addSection:objectSection];
 
// Push the detail view normally here (assuming self is within a UINavigationController)
[self.navigationController pushViewController:[self detailViewController] animated:TRUE];
}
 
 
 
  • Levous2
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0

Re: autoGeneratePropertyDefinition​s not building second level relationship 1 year, 4 months ago #2

Guess what?! Figured it out using your documentation. Go figure...

Relavent code
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// get the checklist item for index path
CheckListItem *item = (CheckListItem *)[self.fetchedResultsController objectAtIndexPath:indexPath];
 
// create a generic UITableViewController to use for detail view
[self setDetailViewController:[[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped ]];
 
// create a table view model for sensible tableview
[self setDetailViewModel:[SCTableViewModel tableViewModelWithTableView:[self detailViewController].tableView
withViewController:[self detailViewController]]];
 
 
// Create a class definition for CheckListItem
SCClassDefinition *checkListItemSCClassDef = [SCClassDefinition definitionWithEntityName:@"CheckListItem"
withManagedObjectContext:[self managedObjectContext]
autoGeneratePropertyDefinitions:YES];
 
 
// Create a class definition for CheckListItemGroup
SCClassDefinition *checkListItemGroupSCClassDef = [SCClassDefinition definitionWithEntityName:@"CheckListItemGroup"
withManagedObjectContext:[self managedObjectContext]
autoGeneratePropertyDefinitions:YES];
 
// Create a class definition for CheckList
SCClassDefinition *checkListSCClassDef = [SCClassDefinition definitionWithEntityName:@"CheckList"
withManagedObjectContext:managedObjectContext
autoGeneratePropertyDefinitions:YES];
 
 
// associate the CheckListItemGroup def with the CheckListItem def
SCPropertyDefinition *checkListItemGroupPropertyDef = [checkListItemSCClassDef propertyDefinitionWithName:@"checkListGroup"];
[checkListItemGroupPropertyDef setType:SCPropertyTypeObject];
[checkListItemGroupPropertyDef setTitle:@"Group"];
[checkListItemGroupPropertyDef setAttributes:[SCObjectAttributes attributesWithObjectClassDefinition:checkListItemGroupSCClassDef]];
 
// associate the CheckList def with the CheckListItemGroup def
SCPropertyDefinition *checkListPropertyDef = [checkListItemGroupSCClassDef propertyDefinitionWithName:@"checkList"];
[checkListPropertyDef setType:SCPropertyTypeObject];
[checkListPropertyDef setTitle:@"List"];
[checkListPropertyDef setAttributes:[SCObjectAttributes attributesWithObjectClassDefinition:checkListSCClassDef]];
 
 
// Create an SCObjectSection for the detail model
SCObjectSection *objectSection = [SCObjectSection sectionWithHeaderTitle:nil
withBoundObject:item
withClassDefinition:checkListItemSCClassDef];
 
// add the section to the tableview controller's table model
[[self detailViewModel] addSection:objectSection];
 
// Push the detail view normally here (assuming self is within a UINavigationController)
[self.navigationController pushViewController:[self detailViewController] animated:TRUE];
}
 
 


Very nice work, Tarek!
  • Levous2
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0

Re: autoGeneratePropertyDefinition​s not building second level relationship 1 year, 4 months ago #3

Great! Also hope to have your feedback on STV 2.0 when you use it later on
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
Time to create page: 1.90 seconds