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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:12:58+00:00 2026-06-16T13:12:58+00:00

I have a view that implements UITextInput and I added support for undo. Right

  • 0

I have a view that implements UITextInput and I added support for undo. Right now each individual key stroke or backspace is recorded as an undoable event.

I know that I can group events and I can open an undo group with the first key stroke. But where would I go and close the group? If the group is open when the user shakes the device I get an exception. You cannot have an open group when doing undo.

I would somehow need to close the open group right before the NSUndoManager instance displays the action menu.

Do I need to subclass NSUndoManager to do that? Or does anybody have a smart idea how I get to close the typing undo group in time before the action?

Note: first responder does not resign when showing the undo actions.

Actually it looks to me like normal text input leaves the typing group somehow open, because if you cancel the undo/redo alert, then you can continue typing and all those keystrokes can subsequently be undone together.

I guess I don’t understand when to group actions and whether and when you need to close a group.

Update: I found the following to be working: I have created a subclass of NSUndoManager that keeps track of the number of open groups. On -undo I’m closing all open groups to avoid the exception and then call [super undo]

#import "DTUndoManager.h"

@implementation DTUndoManager
{
    NSUInteger _numberOfOpenGroups;
}

- (void)beginUndoGrouping
{
    _numberOfOpenGroups++;

    [super beginUndoGrouping];
}

- (void)endUndoGrouping
{
    _numberOfOpenGroups--;

    [super endUndoGrouping];
}

- (void)closeAllOpenGroups
{
    while (_numberOfOpenGroups>0)
    {
        [self endUndoGrouping];
    }
}

- (void)undo
{
    [self closeAllOpenGroups];

    [super undo];
}

#pragma mark - Properties

@synthesize numberOfOpenGroups = _numberOfOpenGroups;

@end

Whenever a new operation begins, like changing paragraph style, I call [self.undoManager closeAllOpenGroups] which causes the undo group for the typing to be closed.

in the -deleteBackward: and -insertText: methods I know that a new typing block needs to be be started:

- (void)insertText:(NSString *)text
{
    DTUndoManager *undoManager = (DTUndoManager *)self.undoManager;
    if (!undoManager.numberOfOpenGroups)
    {
        [self.undoManager beginUndoGrouping];
    }

Now that is not too much extra code, but I was hoping to not having to work with my own subclass for DTUndoManager… so I’m open for suggestions.

  • 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-06-16T13:12:59+00:00Added an answer on June 16, 2026 at 1:12 pm

    My solution is contained in the update to the question.

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

Sidebar

Related Questions

I have a partial view (UserControl) that implements a simple pager in my Asp.Net
This has me scratching my head. I have a view controller that implements UIPopoverControllerDelegate
I have a custom view controller that implements the from UITableViewDataSource and UITableViewDelegate protocols.
I have an ASP.NET page that implements my view and creates the presenter in
I have a view model that implements IValidatableObject that contains a string and a
I have written a MVP project where the View is a WinForm that implements
I have a JScrollPane with a JPanel that implements Scrollable as its viewport view.
I have a view that implements the INavigationAware interface. This interface has the OnNavigationFrom
I have a view-scoped bean that implements Serializable , and a UIComponent passed in
I currently have a view controller that implements ASIHTTP for handling API calls. My

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.