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 7664887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:25:08+00:00 2026-05-31T14:25:08+00:00

Could you please help me with the following I writing an app using CoreData

  • 0

Could you please help me with the following

I writing an app using CoreData and have two view controllers.

ControllerA is a table view and just lists the data
ControllerB is a view controller containing several UITextFields

To edit a row on ControllerA I set a property on ControllerB passing my CoreData entity model object
eg.

viewControllerB.item = [self.fetchedResultsController objectAtIndexPath:indexPath];

Once this is edited, the contents of item on ViewControllerB is passed back to ViewControllerA via delegate and saved.

This works fine, The bit i’m struggling with is the best way of adding a new item to CoreData without setting up the managedObjectContext on ViewControllerB.

I have tried passing a new object with

ItemData *item = [NSEntityDescription insertNewObjectForEntityForName:@"ItemData" inManagedObjectContext:self.managedObjectContext];
viewControllerB.item = item;

this works if I enter the form on ViewControllerB with data, but if I cancel the view and pop it off i’m left with a (null) object in CoreData.

I also tried instantiating the CoreData ItemData object using a standard init, but now understand this won’t work because CoreData doesn’t understand the context and also doesn’t have getter/setters for the properties.

What is best practice for this situation?

1) Should I just pass managedObjectContext to viewControllerB?
2) Create a model class to hold the values from the form and pass that back and then deal with CoreData stuff?

3) or is there a correct way of doing what i’m trying to do?

I’m loosely following iOS Apprentice 2 to deal with Storyboards etc, but in this a model class is passed back and forth which I know works fine, its the CoreData side thats the problem.

I hope the above is clear and that the terminology i’ve used is correct.

Look forward to any help.

  • 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-31T14:25:09+00:00Added an answer on May 31, 2026 at 2:25 pm

    this works if I enter the form on ViewControllerB with data, but if I cancel the view and pop it off i’m left with a (null) object in CoreData.

    If you close the view you need to delete the object if you don’t want it to stay. So if someone hit’s “abort” in on your view you should call

    [self.managedObjectContext deleteObject:theManagedObject];
    

    There are many possible ways of passing the managed object context between controllers. Your AppDelegate should have the managed object context as a property.
    If controller a has a pointer to the context you could just pass this into an (nonatomic, weak) property of controller B.

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

Sidebar

Related Questions

Could anyone please help me using C# Api in Z3. I have no idea
Could someone please help me with the following problem: There are two classes MainForm
Could someone please help me out with the following problem in java. I have
I wonder if anyone could please help me I have been using HTML tidy
could soemone help me with the following condition, please? I'm trying to compare $price
Could you please help me to get image upload working on a view with
Could someone please help me in here, I'm just a beginner who want to
Could somebody please help me get Clang up and running? (I don't have 3.2)
Could anyone please help me convert this code to vb.net, I have tried it
I need to fix the following, could please help me? $return .= <a href='<?php

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.