0

I am building an iPhone app with Objective C. In my app, I am drawing the strokes on image and want to implement the undo and redo functionalities.

I have used NSUndoManager for this. With this I am able to undo my drawing at one level down, but my requirement is to undo the drawing at its lowest possible level (or at least minimum 10 level down). I had already set the setLevelsOfUndo to 10 but it does not work.

I'm using the following code:

- (void)UnDoImage1:(UIImage*)image
{
    if (capturedImage.image != image)
    {
        [self.managedObjectContext.undoManager undo];
        [[self.managedObjectContext.undoManager prepareWithInvocationTarget:self] UnDoImage1:capturedImage.image];
        [capturedImage release];
        capturedImage.image = [image retain];
    }
}

Please let me know where I am incorrect. I have already Googled for this for a long time but did not find the exact cause of failure of the functionality.

iHunter
  • 6,205
  • 3
  • 38
  • 56
Mandeep Kaur
  • 183
  • 4
  • 17

1 Answers1

0

I do not believe that you can use prepareWithInvocationTarget: with an object as a Parameter. Its not going to Keep a copy of capturedImage.image around for the Undo/Redo Stack. So Since you are releasing it and setting it to the new image, the reference to the original is lost and you will just be calling UnDoImage1: with the current capturedImage.image

If thats the only thing you are looking to undo/redo, then I would look at registerUndoWithTarget:selector:object: it will hold onto a reference of capturedImage.image.

Scott<-

scooter133
  • 1,297
  • 1
  • 15
  • 29