I created an App without Core Data. The App has a lots of functions such as manipulating views with gestures, colors and texts.
What I want to do is using the undo and redo functions.
I read everything about Core Data and NSUndoManager and I have problems to understand it, because everything I am trying to do...don't work.
My question is: is it possible to use NSUndoManager without Core Data?
And: how can I realize undos for the views?
One operation can change my Object called aView (UIImageView) I register the information in the undoManager
EDIT
- (IBAction)rotationDetected:(UIRotationGestureRecognizer *)gestureRecognizer {
static CGFloat initialRotation;
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){
initialRotation = atan2f(gestureRecognizer.view.transform.b, gestureRecognizer.view.transform.a);
}
CGFloat newRotation = initialRotation + gestureRecognizer.rotation;
aView.transform = CGAffineTransformMakeRotation(newRotation);
//undo
[self.undoManager registerUndoWithTarget:self selector:@selector(rotationDetected:)object:aView];
[self.undoManager setActionName:NSLocalizedString(@"viewChanged",@"title undo")];
}
And the undo Method which is called by a clicked Button is described here:
-(void)undo: (id) sender{
[aView.undoManager undo];
[[self undoManager] undo];
}
If I insert a if-clause asking if undoManager.canUndo == YES, it returns that undoManager can NOT undo.
That means that the undoManager is nil, But why?
Did I miss something?