Welcome, Guest
Username Password: Remember me

Get reference to new Core Data object
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Get reference to new Core Data object

Get reference to new Core Data object 1 year, 5 months ago #1

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!
Matthew
  • skoota
  • OFFLINE
  • Expert Boarder
  • Posts: 89
  • Karma: 2

Re: Get reference to new Core Data object 1 year, 5 months ago #2

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.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Get reference to new Core Data object 1 year, 5 months ago #3

That's great. Thanks Tarek
  • skoota
  • OFFLINE
  • Expert Boarder
  • Posts: 89
  • Karma: 2
  • Page:
  • 1
Time to create page: 0.75 seconds