Reputation: 799
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?
Upvotes: 0
Views: 214
Reputation: 17014
Yes, you can use NSUndoManager
separately from Core Data. Plenty of info out there about NSUndoManager.
You need to do more reading and understand what NSUndoManager
can and can't do for you and see how that would fit in with UIViews etc. Perhaps forget about Core Data for the moment and concentrate on NSUndoManager
.
"because everything I am trying to do...don't work" -- if you're having specific problems you can ask questions here on StackOverflow about them. We can't help you with specifics if you only say "it doesn't work".
Outside of the specifics of NSUndoManager
, there are design patterns related to undo and redo operations, for example the Command Pattern. See e.g. Best design pattern for "undo" feature.
Upvotes: 0