我开发了一个应用程序,我可以在其中应用查找过滤器。现在我想创建一个撤销按钮,它将重置原始图像,该图像是在imageView中加载图像后保存的。我有这段代码:
- (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];
}
}
但是当我按下撤销按钮时,imageView将被关闭。
我希望有人可以帮助我。
答案 0 :(得分:0)
尝试使用
[self.imgView setImage:image];
而不是
[self->imgView setImage:image];