gpt4 book ai didi

ios - 错误:无效方法'undo:'不应该返回值

转载 作者:行者123 更新时间:2023-12-01 18:14:44 25 4
gpt4 key购买 nike

我在以下代码行中收到此错误(无效方法'undo:'不应返回value):

return image;

有什么问题,有人知道该错误的解决方案吗?

代码:
- (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->_imagView setImage:image];
return image;
}

编辑:

如果点击了“撤消”按钮,我该怎么说呢?

码:
- (IBAction)undo:(id)sender

{

}
- (UIImage*)loadImage
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
@"test.png" ];
UIImage* image = [UIImage imageWithContentsOfFile:path];
return 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];
}
}

最佳答案

您不能从具有void返回类型的方法中返回值。 IBAction实际上只是void

除了尝试返回它之外,您还需要对image进行其他操作。

关于ios - 错误:无效方法'undo:'不应该返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23273166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com