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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:03:08+00:00 2026-05-16T00:03:08+00:00

I have been trying to design the Undo/Redo functionality in one of my app

  • 0

I have been trying to design the Undo/Redo functionality in one of my app using NSUndoManager class and seeing some design difficulties.
In my app, I just have one method

-(IBAction) addLastBall:(Ball *)ball

So, when a user chooses a button in the UI, I add a ball object to my array list. However, I don’t have any action button to remove a ball, this is the design of the UI workflow and can’t be changed.
So, to implement a undo I called the following piece of code inside the addLastBall method

[undoManager registerUndoWithTarget:self selector:@selector(removeBall:) object:ball];

After doing this, removeBall method gets called with the ball object when the user tried to perform the undo. All is good for now.
But, I am not sure how to handle the redo part now, when the user tries to redo, I am not sure which method would get called, because I need to add the ball object the user just removed using the undo operation.
Any insights would be very helpful.

Thanks so much.

  • 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-16T00:03:09+00:00Added an answer on May 16, 2026 at 12:03 am

    A redo simply performs the undo actions registered while the corresponding undo was executing. Therefore, the most straightforward solution is to simply to register an undo action in the removeBall: method.

    - (void)removeBall:(Ball *)ball {
        [undoManager registerUndoWithTarget:self 
                                   selector:@selector(addLastBall:)
                                     object:ball];
        ...
    }
    

    Note that it is sometimes clearer to useprepareWithInvocationTarget: to register undo actions:

    [[undoManager prepareWithInvocationTarget:self] addLastBall:ball];
    

    By the way, be sure to keep the retain count of the ball above zero in the removeBall: method — the undo manager will not retain the ball for you, and if it gets deallocated, then undoing the remove will crash.

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

Sidebar

Related Questions

I have been trying to find a good-looking design using Aero in Delphi 2010.
I have been trying to design a WCF file upload service and am getting
With the addition of the Tuple class in .net 4, I have been trying
Hi, i have been having some problems using JSON data in flash builder lately
I am new to design patterns, but I have been trying hard to implement
I'm a developer with limited HTML/CSS design experience. I have been stuck trying to
I have a question that I've been trying to answer for some time now
I have been trying to design a system in Java where I can track
I have been trying to subclass the UINavigationController class for modifying things like background
I have recently been trying to learn about basic design principles and the OCP

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.