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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:23:39+00:00 2026-05-22T23:23:39+00:00

//Edit: Really, nobody has any suggestions or thoughts on this? Have I asked the

  • 0

//Edit: Really, nobody has any suggestions or thoughts on this? Have I asked the question wrongly somehow?//

My iPhone app has a single managedObjectContext with a moderately complicated data model. I’m now adding undo functionality, and am not clear on how best to handle nested viewControllers (as each layer might modify the data model).

Apple’s docs point out:
“Consider an application that displays
a list of books, and allows you to
navigate to a detail view that in turn
allows you to edit individual
properties of the book (such as its
title, author, and copyright date).
You might create a new book from the
list screen, navigate between two
other screens to edit its properties,
then navigate back to the original
list. It might seem peculiar if an
undo operation in the list view undid
a change to the author’s name that was
made two screens away rather than
deleting the entire book.”


So what’s the best way to implement this? Currently, I’m thinking to have each viewController keep its own undoManager, which would be active whenever it’s on the screen. So my understanding is that this would require the following steps (for each VC):

  • Add a property: myUndoManager
  • Add an undoManager method returning myManagedObjectContext.undoManager;
  • In viewDidAppear: myManagedObjectContext.undoManager = myUndoManager; //create first if nil
  • In viewWillDisappear: myManagedObjectContext.undoManager = nil;
  • On memory warning: [self.undoManager removeAllActions ];
  • On dealloc: self.myUndoManager = nil;
  • For each model change: [self.undoManager setActionName:NSLocalizedString(@“XXX”,@“”)];
  • CoreData will handle the actual undo/redo postings

In addition, I have to remain firstResponder:

  • In viewDidAppear: `[self becomeFirstResponder]’
  • Add canBecomeFirstResponder method returning YES
  • In viewWillDisappear: [self resignFirstResponder];
  • Re-enable firstResponder upon subViews resign (e.g. textFields)

So far, that seems like it works, even across load/unload cycles, and is nicely self-contained, but I have several questions:

  • First, is this the best practice for implementing undo across multiple VCs?
  • Will I get in trouble with my child VCs not doing their undos prior to my doing my earlier ones?
  • If so, does that list capture everything I need to do?
  • Will ManagedObjectContext get confused with multiple UndoManagers being active?
  • Do I need to call ProcessPendingActions before swapping undoManagers?
  • 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-22T23:23:40+00:00Added an answer on May 22, 2026 at 11:23 pm

    Each view controller can have its own undo manager. A controller should only be responsible for the fields that it directly changes. Once you back out of the corresponding view, the controller should be released and the undo manager with it.

    Let’s say you have 3 levels. Level 1 represents the entire record, level 2 represents a subset of data from level 1, and level 3 represents a subset of data from level 2.

    Once you back out of level 3, you’ve basically said I accept and you shouldn’t need to undo any of that data in level 2. This changed data should only show up as read-only data in level 2 if it shows at all. Similarly, once you back out of level 2, you should release its undo manager.

    Back in level 1, since it represents the entire record, why not have a Cancel button instead of trying to undo (or in addition to, depending on what your level 1 controller does)?

    Then, if you want to cancel the entire operations you can send a message like the following to your managed object context:

    [myMOC refreshObject:theEditedObject mergeChanges:NO];
    

    This will effectively roll back the entire record.

    If, for whatever reason, you decide to keep level 3’s undo manager around while you’re in level 2 and you do a rollback at level 2, only the data pertaining to level 2’s undo manager would be rolled back. Level 3’s undo manager is separate and Core Data does not see the undo managers as nested.

    A managed object context can’t get confused due to multiple undo managers because it can only keep track of one at a time via its setUndoManager: method.

    You probably won’t need to use processPendingChanges unless somehow a rollback is taking place before the completion of the event loop after a change has been made. I wouldn’t worry about this unless your undo only restores some of the data that is supposed to be recorded with the undo manager up to that point.

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

Sidebar

Related Questions

EDIT: This question was initially too general, I think. So What I really need
Edit: Since it appears nobody is reading the original question this links to, let
I posted another one on this,, but i had to edit it really much...
So this has just been driving me nuts! I have looked through tons of
I have a question about this question . I posted a reply there but
Is the documentation for Rich Edit Controls really as bad (wrong?) as it seems
Edit: When I say SQL Server, I'm really talking about the Management Studio. Sorry
I installed gvim on windows vista and got really excited to edit EVERYTHING with
Edit: Translated I have a RSS-feed that i want to parse. It's a podcast
EDIT: I have a table with 3 rows like so. ID NAME REV 1

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.