I have developed an app, where I can apply lookup filters. Now I want to create an undo button, which will reset the original image, which is saved after loading the image in the imageView. I have this code:

- (IBAction)undo:(id)sender
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                         NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString* path = [documentsDirectory stringByAppendingPathComponent:
                      @"test.png" ];
    UIImage* image = [UIImage imageWithContentsOfFile:path];
    [self->imgView setImage:image];
}




- (void)saveImage: (UIImage*)image
{
    if (image != nil)
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString* path = [documentsDirectory stringByAppendingPathComponent:
                          @"test.png" ];
        NSData* data = UIImagePNGRepresentation(image);
        [data writeToFile:path atomically:YES];
    }
}

But when I press the undo button, the imageView will be closed.

I hope someone can help me.

有帮助吗?

解决方案

Try to use

[self.imgView setImage:image];

instead of

[self->imgView setImage:image];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top