我似乎在删除UIScrollView中的图像时遇到问题。我能够将其从NSDocumentDirectory
中移除,但它仍然保留在视图中。如何在按下按钮时将其删除。这是我的代码:
- (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];
}
答案 0 :(得分:3)
您需要从超级视图中删除视图,如下所示
//In your button clicked function
- (IBAction)buttonClicked:(id)sender {
UIButton *button = (UIButton *)sender;
[button removeFromSuperView];
}
答案 1 :(得分:0)
我想完成你的删除选项后。你没有重新加载你的观点。所以我保持这种形象。