iphone - 删除 View 中的图像

标签 iphone ios xcode

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

相关文章:

ios - 触发UIApplicationWillTerminateNotification以“停止” Xcode操作

javascript - 如何检查应用程序是否从 Safari 中的 JS 安装?

iphone - 尝试使用对象初始化 NSArray 时出错?

iphone - 使用矢量化为 iPhone 编译 Eigen 库

ios - 在 UITableView 中显示 Firebase 数据

iphone - iPad 方向未正确返回

ios - 如何在总步骤中获取CMMotionActivity

ios - 程序 map 生成 - SpriteKit 和 GameplayKit

objective-c - CI 与 iOS (Objective-C) 项目和 Hudson

ios - MKPolyline 的自定义 "Callouts"