我似乎在删除 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/