Jump to content

- - - - -

Core Data - skip list view and go straight to detail view

  • Please log in to reply
4 replies to this topic

#1 halldorg


    Jr. Member

  • STV 5.0 Std
  • PipPip
  • 26 posts
Reputation: 5

Posted 28 May 2013 - 06:30 PM

I have a Core Data model and have found STV to work very well with Core Data, thanks.


The editing part is brilliant and I the part I think will save me loads of time, I do however like to use other ways such as collectionviews and other ways to display the "lists", only to call on STV to edit indivitual "objects"/records.


I can't see at a glance how a tableview controller can be configured to skip the "list" and go straight to "Detail" mode.


Here is a small sample(not actual but shows what I am after):



    [super viewDidLoad];

    NSManagedObjectContext *managedObjectContext = [[LDAppDelegate sharedDelegate] managedObjectContext];
   // I know which "district" i want to edit
   NSPredicate *pred = [NSPredicate predicateWithFormat:@"districtID ==%@", @"NONE"];
SCEntityDefinition *districtDef = [SCEntityDefinition definitionWithEntityName:@"District" managedObjectContext:managedObjectContext propertyNamesString:@"District Details:(districtID,districtName)"];
   districtDef.requireEditingModeToEditPropertyValues = TRUE; 
districtDef.orderAttributeName = @"districtName";
SCPropertyDefinition *descPropertyDef = [districtDef propertyDefinitionWithName:@"districtName"];
descPropertyDef.title = @"District Title";
descPropertyDef.type = SCPropertyTypeTextView;

// Create and add the objects section
SCArrayOfObjectsSection *objectsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil entityDefinition:districtDef filterPredicate:pred] ;
objectsSection.addButtonItem = self.addButton;

[self.tableViewModel addSection:objectsSection];


Problem is that why the detail section works perfectly for editing I can't see a way to skip straight past the single record that is displayed in "list" and into the detail editing.




#2 ozie



  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169

Posted 28 May 2013 - 07:19 PM

[self.tableViewModel generateSectionsForObject:<yourmanagedObject> withDefinition:districtDef];

<yourmanagedObject> is the one object item in the entity



if you dont know what the object is there is a method to call to pretend to tap the cell there are dispatch events that might come in handy

objectsSection dispatchEventAddNewItem
objectsSection dispatchEventRemoveRowAtIndexPath:<#(NSIndexPath *)#>
objectsSection dispatchEventSelectRowAtIndexPath:<#(NSIndexPath *)#>

Edited by ozie, 28 May 2013 - 07:26 PM.

  • Tarek likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.

#3 halldorg


    Jr. Member

  • STV 5.0 Std
  • PipPip
  • 26 posts
Reputation: 5

Posted 29 May 2013 - 10:40 AM

Thanks ozie,

It does populate the view but does not add the automatic toolbar and sections that have been defined - it still behaves like a list view instead of a detail editiing view.


Is there a property or another way to force the view to behave like a detail view?



Edited by halldorg, 30 May 2013 - 03:12 PM.

#4 Tarek


    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452

Posted 24 June 2013 - 07:34 AM

Hi Halldor,


Continuing on Ozie's solution, the following code should do the trick for you:


// this is your own custom method that you should call from your code
- (void)displayDetailViewForObject:(NSObject *)object withDefinition:(SCDataDefinition *)definition
  SCTableViewController *detailVC = [[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
  detailVC.navigationBarType = SCNavigationBarTypeEditRight;
  [detailVC generateSectionsForObject:object withDefinition:definition];
  // assuming current view controller is inside a UINavigationController
  [self.navigationController pushViewController:detailVC animated:YES];


One other solution I've been also thinking of is to create a dummy SCArrayOfObjectsSection in the root view controller that is not actually added to any table view! You would then instruct SCArrrayOfObjectsSection to automatically display the detail view for any given object by calling its 'dispatchEventSelectRowAtIndexPath' method. The only missing part here is that since our dummy SCArrayOfObjectsSection isn't associated with any table view, there is no way for it to get hold of the navigation controller and push the detail view on the stack. We can add a new feature in our upcoming release that would enable you to do just that. Please let me know what you think about this and if you have any other ideas that would make it even easier.

#5 halldorg


    Jr. Member

  • STV 5.0 Std
  • PipPip
  • 26 posts
Reputation: 5

Posted 19 September 2013 - 02:50 PM

Thanks Tarket,

This works as it should - brings up the correct detail view and allows me to edit.


The Back button though seems to create an empty view - probably something i have to override to get control to return back to my view?



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users