gpt4 book ai didi

iphone - 删除 View 中的图像

转载 作者:行者123 更新时间:2023-11-28 20:34:27 25 4
gpt4 key购买 nike

我似乎在删除 UIScrollView 中的图像时遇到了问题。我能够将其从 NSDocumentDirectory 中删除,但它仍保留在 View 中。如何在按下按钮时将其删除。这是我的代码:

- (IBAction)buttonClicked:(id)sender {
UIButton *button = (UIButton *)sender;
[_images objectAtIndex:button.tag];
[_images removeObjectAtIndex:button.tag];

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.png", button.tag]];
[fileManager removeItemAtPath: fullPath error:NULL];

}

最佳答案

您需要像下面这样从 super View 中删除 View

//In your button clicked function
- (IBAction)buttonClicked:(id)sender {
    UIButton *button = (UIButton *)sender;
[button removeFromSuperView];
}

关于iphone - 删除 View 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11078439/

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