Jump to content

- - - - -

Get reference to new Core Data object

  • Please log in to reply
2 replies to this topic

#1 Matthew Purcell

Matthew Purcell

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 84 posts
Reputation: 2

Posted 14 December 2010 - 12:36 AM

Hi All,

I have my STV bound to a Core Data entity and the STV lists each object within the entity. There is of course an Add (+) button allowing the user to add a new object. I have somewhat customised the detail view controller that appears to add a new object by adding a custom table view footer with a segmented control (this customisation is done in the - (void)tableViewModel:(SCTableViewModel *) tableViewModel detailViewWillAppearForSectionAtIndex:(NSUInteger) index withDetailTableViewModel:(SCTableViewModel *) detailTableViewModel delegate method).

I need some way to get a reference to the newly created Core Data object so that I can manually set the object's attribute which relates to the custom control within the table view footer.

This is easy when editing an existing object, as I can get a reference to the object using the following code within the detailViewWillAppearForRowAtIndexPath method:

SCArrayOfObjectsSection *objectsSection = (SCArrayOfObjectsSection *)[tableViewModel sectionAtIndex:indexPath.section];
CoreDataObject *coreDataObjectForCell = (CoreDataObject *)[objectsSection.items objectAtIndex:indexPath.row];

However, I don't know how to get the reference to the newly created object. I guess this all depends on when the object is created - when the user taps the Add (+) button or when the Done button is tapped to dismiss the view. Either way, any assistance to get the reference would be appreciated.

P.S. I realise that I could use a SCPropertyTypeSegmented within the STV itself. However, I need to put the control within the footer for other reasons specific to my implementation (plus, in other table views I use other custom controls so this question has wider applicability).

Thanks for any help!

#2 Tarek


    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452

Posted 15 December 2010 - 09:01 AM

Hi Matthew,

I don't know if I fully understand your question, but doesn't the SCTableViewModelDelegate method called "tableViewModel:itemCreatedForSectionAtIndex:item:" give you what you want via its "item" parameter? (you just need to cast it into an NSManagedObject) Please tell me if what I understood is correct.

#3 Matthew Purcell

Matthew Purcell

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 84 posts
Reputation: 2

Posted 16 December 2010 - 12:07 AM

That's great. Thanks Tarek :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users