问题
I have a Drawing App of sorts. I want to Implement Undo/Redo. Though I'm running into difficulty with storing the Original and New Values for the Undo/Redo.
With Gestures I need to store a Few things: transform, Center, for the Properties Dialog, I need to store many more, Color, Font, Font-Size, Outline, Outline Color, the Text It self, etc.
I've created a NSMutableDictionary
of the Attributes that the user can change in a Single Gesture/Properties Popover.
I wanted to use Rob's Answer for NSUndoManager and Rotation Gesture though using his Solution works with CGAffineTransform
, which when sent as a parameter for the prepareWithInvocationTarget
, its not an object and just puts a copy of the CGAffineTransform
struct on the Undo/Redo stack.
Though when using the prepareWithInvocationTarget
with my NSMutableDictionary
the Dictionaries I'm passing in (OriginalAttribs, newAttribs) are not retained. I cannot have them as local iVars as they will change with each action on a drawing object.
Seems like I want to use retainArguments
as part of NSInvocation
though I don't really want to retain them. I need a copy of them.
Its the Gestures that make this Difficult as I can't keep setting the OrigianlCenter, OriginalTransform as it changes while the gesture is active.
UPDATE I found this link and it seems to be similar to what I want to do.
I setup my NSUndoManager like this:
//Needed to get access to UndoManager
NSUndoManager * undoManager = [(IoScreenEditorViewController * )UIAppDelegate.ioMainViewController.currentViewController undoManager];
//Need to Store our Center as a NSValue
[undoManager prepareWithInvocationTarget:self];
[undoManager forwardInvocation:anInvocation ];
I then get a runtime error:
-[NSUndoManager undoAttributesWithOriginalAttributes:newAttributes:]: unrecognized selector sent to instance 0xeedcbd0
undoAttributesWithOriginalAttributes:newAttributes:
is the selector that I setup for my NSInvocation Object. According to the Documentation here, it says that it should pass it along to self (the Target), not the undo manager self?
来源:https://stackoverflow.com/questions/9793078/using-nsundomanager-with-preparewithinvocationtarget-gestures-and-objects