UA-17470720-3

Jump to content


Photo
- - - - -

Saving Changes - SCTableViewModel created with generateSectionsForObject

models sections general

  • Please log in to reply
3 replies to this topic

#1 sminar

sminar

    Jr. Member

  • STV 3.0 Std
  • PipPip
  • 12 posts
Reputation: 1
Good

Posted 20 December 2013 - 02:54 AM

I have a simple SCTableViewModel in an SCTableViewController.

I am stumped, trying to properly save changes.

 

The model is generated using generateSectionsForObject:, passing a Parse User object and an appropriate SCClassDefinition.

 

The Parse User object contains a handful of NSString properties that I want to display and allow the user to edit.

 

It's effectively a single object editor, similar to an SCTableViewModel built with an SCUserDefaultsDefinition.

No detail views are generated, editing is taking place in the cells of the main table view.

 

The SCTableViewModel is displayed properly and I can edit the individual cells, but I can't figure out the correct way to hook into the SCT lifecycle to save the data.

 

Since I'm not an SCArrayOfItemsSection, I can't use the didUpdateItem action for a section.

 

I have made my SCTableViewController implement the SCTableViewModelDelegate protocol, setting self.TableViewModel.delegate = self in viewDidLoad.

I implemented:

 

- (void) tableViewModel:(SCTableViewModel *) tableViewModel itemEditedForSectionAtIndexPath:(NSIndexPath *)indexPath item:(NSObject *)item;

- (void)tableViewModel:(SCTableViewModel *)tableModel valueChangedForRowAtIndexPath:(NSIndexPath *)indexPath;

- (void)tableViewModel:(SCTableViewModel *)tableModel valueChangedForSectionAtIndex:(NSUInteger)index;

 

I've only put a logging statement in each of the above.  Interestingly, only valueChangedForRowAtIndexPath appears to be getting called.  It gets called at every change to a cell (every character change while a user is typing) so I don't really want to save the object in this method.

 

I suspect I could re-write the code using SCParseComDefinition, but it seems like there's a solution that I'm missing in my current implementation.

 



#2 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 20 December 2013 - 03:37 PM

what about a DONE button ?

 

what about these actions

self.tableViewModel.sectionActions.willUpdateItem

self.tableViewModel.sectionActions.willInsertItem

self.tableViewModel.sectionActions.willDeleteItem


Edited by ozie, 20 December 2013 - 03:42 PM.

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


#3 sminar

sminar

    Jr. Member

  • STV 3.0 Std
  • PipPip
  • 12 posts
Reputation: 1
Good

Posted 20 December 2013 - 07:10 PM

Would love to use a DONE button.

 

I'm not sure of the best way to add the DONE button once the editing has begun / data is "dirty".  I don't really want the DONE button to be visible until the user makes a change.

 

I looked at using

 

self.tableViewModel.sectionActions.willUpdateItem

self.tableViewModel.sectionActions.willInsertItem

self.tableViewModel.sectionActions.willDeleteItem

 

but according the to documentation, they are only available to SCArrayOfItemsSection subclasses.

Having created the model using generateSectionsForObject: with a single NSObject, I believe I'm an SCObjectSection, which is not a subclass of SCArrayOfItemsSection.

 

I'm basically attempting to create a form for a single object.  SCUserDefaultsDefinition creates a tableViewModel that works in this manner.  Not sure if I can get the same functionality using generateSectionsForObject:.



#4 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 20 December 2013 - 07:25 PM

never hurts to try.. so many things still inherit from the same things that it can just work


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






Also tagged with one or more of these keywords: models, sections, general

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users