0
votes

I have a function for undo who works good. My app is a photo editor with multiple effect. When i add multiple effect to my photo and i undo all this effect, it works very good BUT when i want add again a filter/effect and i want undo again it don't work. I mean my undo function work only one time.

Can someone tell me why it work only one time ?

there is my function who work :


    - (void)updateImage:(UIImage*)Images {

        [undoManager registerUndoWithTarget:self selector:@selector(updateImage:) object:Images];

        _imageView.image = Images;

    }

    - (void)pushedUndoBtn:(id)sender
    {
       [undoManager undo];
    }

There is how i reference my undo manager :


    @implementation _CLImageEditorViewController
    {

        NSUndoManager * undoManager;

    } 

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        undoManager = [[NSUndoManager alloc] init];

    }

1
How your undoManager is stored in your class? Do you keep a strong reference to it?user7219266
i added more code of how i reference. thanksh.karam

1 Answers

0
votes

You should pass the old image (_imageView.image) to -registerUndoWithTarget:selector:object:, not the new image (Images). You want the undo operation to invoke -updateImage: with the old image to restore the old state. So:

    [undoManager registerUndoWithTarget:self selector:@selector(updateImage:) object:_imageView.image];