0

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?

Studie
  • 799
  • 2
  • 12
  • 20

1 Answers1

0

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.

Community
  • 1
  • 1
occulus
  • 16,959
  • 6
  • 53
  • 76
  • Just code isn't enough either -- you need to say what you expected to happen, what happened. And there's a fine art to posting the correct snippet that allows the problem to be seen. – occulus Dec 05 '12 at 14:37
  • Have you put in NSLogs to see what is getting called and when? – occulus Dec 05 '12 at 14:38
  • therefore I do not understand it. I have everything written in my code, but it does not work. Did I miss something? Maybe in other classes such as in the appdelegate? – Studie Dec 05 '12 at 15:25