UA-17470720-3

Jump to content


Photo
- - - - -

User Categories


  • Please log in to reply
11 replies to this topic

#1 designwerks

designwerks

    Advanced Member

  • STV 5.0 Std
  • PipPipPipPipPip
  • 139 posts
  • LocationKingsville, Ontario, Canada
Reputation: 23
Excellent

Posted 03 January 2015 - 06:07 AM

Folks,

 

Been using STV for a few years.  I have 4 apps that rely heavily on STV.  I've had a few complaints in the App Store that my apps don't allow for users to create their own categories. (No fault of STV - I never learned how to implement)...

 

So here is my scenario...

 

In one of my apps I have Trees, Shrubs, Evergreens, Vines, Groundcovers, Weeds, Azaleas, Rhododendrons etc.  Each one has it's own Entity which seems like too much code since each Category has the exact same info in it except for the category title of Trees, Shrubs, Evergreens etc.... Each has a name, a size, a colour, etc...

 

Right now the code is TreeName, TreeSize, TreeLocation etc. then again for Shrubs it is ShrubName, ShrubSize, ShrubLocation etc. you can see for each entity I have to slightly adjust the name.  I think this is where I am missing the value of having categories set up so that the info is the same that the user fills in, but is organized correctly.

 

So I have two questions,

 

1. How do I code the database to use categories (not like in the task example in core data provided with STV)

2. How to I allow users to create their own additional categories and continue to use the database.

 

Help...



#2 David DelMonte

David DelMonte

    Forum Master

  • STV 4.0 Pro
  • PipPipPipPipPipPipPip
  • 527 posts
Reputation: 41
Excellent

Posted 03 January 2015 - 09:43 AM

I hope this helps you..  The STV version at the time was (iirc) 2.x, so the syntax needs to be updated. I had to allow for user defined categories as well as user-defined properties (if someone wanted to track categories, or currencies or locations, they could. If they didn't, they could (UI)switch them off.

 

My data model looked wild, so here is a simplified version:

 

 

Attached File  Screen Shot 2015-01-03 at 12.40.41 PM.png   88.83K   29 downloads

 

 

The code snip is taken from the RootViewController:

 

 

 




- (void)loadPropertyNames {


//The properties were optional based on user prefs. Switches turned them on and off, so I had to keep track of row numbers:


if ([[NSUserDefaults standardUserDefaults] boolForKey:@"categoryKey"]) {
[propertyNames addObject:@"category"];
rowIndex ++;
categoryRow = [NSNumber numberWithInt:rowIndex];
} 
} 
Add other properties as needed eg
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"currencyKey"]) {
.....
}




- (void)loadClassDefinitions {
// CLASS DEFINITION - MAIN ENTITY
//NSLog(@"%s", __FUNCTION__);
mainDef = [SCClassDefinition definitionWithEntityName:@"MainEntity"  withManagedObjectContext:managedObjectContext
 withPropertyNames:propertyNames];
mainDef.orderAttributeName = @"order";






SCClassDefinition *categoryDef = [SCClassDefinition definitionWithEntityName:@"CategoryEntity" withManagedObjectContext:managedObjectContext withPropertyNames:[NSArray arrayWithObjects:@"name", nil]];
categoryDef.orderAttributeName = @"order";
categoryDef.uiElementDelegate = self;


Add other entities as needed.




// PROPERTY DEFINITION = CATEGORY


SCPropertyDefinition *categoryPropertyDef = [mainDef propertyDefinitionWithName:@"category"];
categoryPropertyDef.type = SCPropertyTypeObjectSelection;
categoryPropertyDef.title =  [NSString stringWithFormat:@"%@", NSLocalizedString(@"CATS", nil)];
SCObjectSelectionAttributes *catAttributes = [SCObjectSelectionAttributes 
    
    attributesWithItemsEntityClassDefinition:categoryDef 
    allowMultipleSelection:NO allowNoSelection:YES];
catAttributes.allowAddingItems = YES;
catAttributes.allowDeletingItems = YES;
catAttributes.allowMovingItems = YES;
catAttributes.allowEditingItems = YES;
catAttributes.placeholderuiElement = [SCTableViewCell cellWithText:NSLocalizedString(@"ADDCAT", @"")];
catAttributes.addNewObjectuiElement = [SCTableViewCell cellWithText:NSLocalizedString(@"ADDCAT", @"")];
categoryPropertyDef.attributes = catAttributes;


Add other properties as needed.


 

 


Edited by David DelMonte, 03 January 2015 - 08:39 PM.

  • Tarek likes this

#3 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 05 January 2015 - 11:07 AM

Please find attached a modified version of our CoreDataApp sample where you can dynamically enter categories. Please let me know if this is what you're looking for.

 

Happy 2015! :)

Attached Files


  • David DelMonte and wizgod like this

#4 designwerks

designwerks

    Advanced Member

  • STV 5.0 Std
  • PipPipPipPipPip
  • 139 posts
  • LocationKingsville, Ontario, Canada
Reputation: 23
Excellent

Posted 09 August 2015 - 06:16 AM

Hi All...

 

It's been a while...

 

I have an issue, that I think is simple to fix (although not sure).

 

When a user enters the database, I want them to first create categories for the database.  Once they have one or more categories, they then proceed to the rest of the database.

 

All works as expected, but all categories display the same info (see screen captures).  The information is not unique.

 

Example:

 

User creates a category named "Trees" (that works)

User creates a category named "Flowers" (that works)

 

User clicks on newly created category named "Trees" and a new controller appears where user can fill in data (that works)...

 

User clicks on newly created category named "Flowers" and the information previously input into the tree category now appears (NOT WORKING)...

 

What am I missing...

 

Thanks Tarek - this is a bit of a twist from what you provided previously to me...

Attached Files



#5 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 09 August 2015 - 07:32 PM

Greetings Program!

 

If I'm looking at the data model correctly, for me, it looks a bit odd having the Category at the top of the hierarchy if you have a 1-1 relationship between CategoryEntity and TaskEntity.

 

If you are starting with creating a CategoryEntity, it should have a 1-Many relationship to TaskEntity.

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 10 August 2015 - 06:29 AM

So is this behavior replicatable in the sample I attached above, or is something specific to your app?



#7 designwerks

designwerks

    Advanced Member

  • STV 5.0 Std
  • PipPipPipPipPip
  • 139 posts
  • LocationKingsville, Ontario, Canada
Reputation: 23
Excellent

Posted 10 August 2015 - 10:07 AM

So is this behavior replicatable in the sample I attached above, or is something specific to your app?

 

Tarek,

 

Your example app is great at showing me how to include categories for first time users to pre populate data.  That is not the issue.  It is in my methodology...

 

I want the user to create categories first, THEN when they create a category or two - click on the newly created category, and THEN continue to add data.  That all works as designed EXCEPT, regardless of the category clicked (once created) the same info is shown across ALL categories.  I don't think it's an STV issue, but rather something in my "hook ups"...

 

Example:

 

User enters app - creates a category named Rock Music and a category named Country Music

 

User then clicks on Rock Music and continues to enter data (lets say) The Rolling Stones etc...

 

Then the user returns and clicks on the category Country Music - but the info The Rolling Stones shows up...

 

So while the core data is saving correctly, it is not respecting the unique category Rock Music Versus Country Music etc...

 

Of course, right now in my example I can click on Country Music and create a new entry but, that new entry will show up in the Rock Music category :(

 

Any ideas based on the images above?  Also, based on wizgod suggestion I did make CategoryEntity, have a 1-Many relationship to TaskEntity.

 

John



#8 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 10 August 2015 - 12:14 PM

Hey John,

 

That all works as designed EXCEPT, regardless of the category clicked (once created) the same info is shown across ALL categories.

 

That is very strange. I tried replicating this using your same exact logic, but couldn't. Do you have a sample, or can you tell me how to replicate this behavior in our bundled CoreDataApp?

 

Thanks!



#9 designwerks

designwerks

    Advanced Member

  • STV 5.0 Std
  • PipPipPipPipPip
  • 139 posts
  • LocationKingsville, Ontario, Canada
Reputation: 23
Excellent

Posted 10 August 2015 - 12:34 PM

I don't mind sending you the project file - how can I do that?



#10 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 10 August 2015 - 03:03 PM

You can create a new support ticket in your client area and privately upload your project there. Please include the exact steps required to reproduce.



#11 designwerks

designwerks

    Advanced Member

  • STV 5.0 Std
  • PipPipPipPipPip
  • 139 posts
  • LocationKingsville, Ontario, Canada
Reputation: 23
Excellent

Posted 11 August 2015 - 05:23 AM

Thanks Tarek,

 

Upload per your instructions.  Like I say, I don't think it's an STV issue, but rather my hook up between controllers...



#12 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 18 August 2015 - 09:25 AM

Hi John,

 

I had an initial look at your project, and I think your issue is that you're not correctly binding the data store when manually creating your own detail views. Here is a code sample of correctly generating a manual detail view for 'Task Steps' in our CoreDataApp bundled app:

 

    SCDataDefinition *taskDef = [self dataDefinitionWithIBName:@"TaskEntity"];
    SCEntityDefinition *taskStepDef = (SCEntityDefinition *)[self dataDefinitionWithIBName:@"TaskStepEntity"];
    self.tableViewModel.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        SCTableViewController *detailVC = [[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
        detailVC.navigationBarType = SCNavigationBarTypeAddEditRight;
        
        SCArrayOfObjectsSection *objectsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:@"Custom TaskSteps Section" entityDefinition:taskStepDef];
        [objectsSection.dataStore bindStoreToPropertyName:@"taskSteps" forObject:cell.boundObject withDefinition:taskDef];
        [detailVC.tableViewModel addSection:objectsSection];
        
        [cell.ownerTableViewModel.viewController.navigationController pushViewController:detailVC animated:YES];
    };

 

Without calling the 'bindStoreToPropertyName:forObject:withDefinition:' method, any taskSteps you add will be viewable from *all* tasks, and not the specific task you have at hand. Please let me know if this helps.


Edited by Tarek, 18 August 2015 - 09:37 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users