Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7097987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:00:06+00:00 2026-05-28T11:00:06+00:00

I have a problem to insertNewObject in an entity being the child in a

  • 0

I have a problem to insertNewObject in an entity being the child in a parent/child relationship. It’s a CoreData app with a local SQLite base. There are 2 entities presented with 2 TableViews on the main window. Using contentSet, the table for the child will only show data relating to the selected parent.

Adding data to the child is done by showing a sheet with a table of items coming from a 3rd entity. User must pick from this table then click Add. On dismissing the sheet, the child table on main window should be updated with a new row. Problem: nothing appears.

Checking the database content with a third-party app, I see that the new data is there but it doesn’t appear on the table view because no info on the relationship with parent was stored, so it doesn’t know to which parent it relates.

My code is missing info about this but I just don’t see how I should program this. In other words: on dismissing sheet, identify which parent is selected and specify this relationship info when inserting the new data in the child. I would appreciate any help.

Here is my code:

  // there are 3 entities: Collectors (parent), CollectedItems (child) and Items.

  // we call the sheet presenting the Items list to pick from
  - (IBAction)showAddItemDialog:(id)sender {
    [NSApp beginSheet:addItemDialog
modalForWindow:window
modalDelegate:self
    didEndSelector:@selector(didEndAddItemSheet:returnCode:contextInfo:)
    contextInfo:nil];
  }

  // we dismiss the sheet by clicking on Cancel or Add
  - (IBAction)dismissAddItemDialog:(id)sender {
[NSApp endSheet:addItemDialog returnCode:([sender tag])];
    [addItemDialog orderOut:sender];
  }

  // depending on clicked button, do nothing or pass selected data
  - (void)didEndAddItemSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo (void *)contextInfo {
    if (returnCode == 0) {
    // do nothing, this is the effect of clicking on Cancel
    }
    if (returnCode == 1) {
    NSString *theName = [[[itemsPickerController selectedObjects] valueForKey:@"itemName"] objectAtIndex:0];
    // above, we get the value from the itemName attribute sleected in the Items list
    NSLog (@"%@", theName);
    // the variable is displayed in the console, so it was correctly selected
    [self addNewItemWithName:theName];
    }
  }

  // we use the passed data to create new object (row) in the CollectedItems entity
  - (id)addNewItemWithName:(NSString *)theName {
    NSEntityDescription *newContent = [NSEntityDescription insertNewObjectForEntityForName:@"CollectedItems" inManagedObjectContext:[self managedObjectContext]];
    [newContent setValue:theName forKey:@"collectedItemName"];
    // above, we insert a new row in CollectedItems, assigning the value theName to the attribute collectedItemName
    return nil;
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:00:07+00:00Added an answer on May 28, 2026 at 11:00 am

    You need to add the relationship between your CollectedItems object you created and its parent the Collectors object. Collectors will have a core data utility method on it (if you have generated the core data managed object classes). It will be called something like addCollectedItemsObject.

    Reloading the tableViews should then update with the correct data – as it now knows the relationship.

    Even better would be to use NSFetchedResultsController to control the data in your tables so that when you update your data model, the tables will automatically reflect the changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem with enum I need make a enum in base class or
I have problem with Joomla layouts in my component..There must be something bad with
I have problem running my app on Android 2.3 (Gingerbread). The app has a
I have problem in uploading .doc file to .Net WCF from my Android app.
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.