user3709183
user3709183

Reputation: 11

Override UITextView Undo

I'd like my subclass of UITextView to stop using it's undo / redo method, so that my custom undo method can take over:

NSUndoManager registerUndoWithTarget:selector:object:

I have yet to work out how to add redo operations to the stack. (despite reading Undo Architecture) Perhaps someone could point me in the right direction?

Upvotes: 0

Views: 1199

Answers (1)

user3709183
user3709183

Reputation: 11

I went and re-read the documentation, and the solution became apparent. I'll explain how this works for those who struggled as I did.

To implement a custom NSUndoManager in a UITextView subclass:

1. Override the NSUndoManager property & synthesize
@property (retain) NSUndoManager *undoManager;
2. Initialize NSUndoManager
self.undoManager = [[NSUndoManager alloc] init];
3. Register Undo Action before change occurs
[self.undoManager registerUndoWithTarget:self selector:@selector(someHandleUndoMethod:) object:(somePre-ChangeObject)];

Note: Redo actions are automatically taken care of.

Upvotes: 1

Related Questions