【发布时间】:2012-04-02 09:03:22
【问题描述】:
我有一个应用程序,其行为有点像照片库。他们从相机胶卷中选择一个图像,图像显示在 UIImageView 中。我总共有 9 个图像视图。现在,我正在尝试添加按下编辑按钮的功能,并允许用户删除照片。我通过在每个图像上放置一个隐藏的 UIButton 来实现这一点,当点击该按钮时,会出现一个 UIAlertView 询问他们是否要删除该图像。在他们单击 UIAlertView 中的“是”后,我希望该特定 UIImageView 停止显示图片,并将每个显示的图片向左移动 1 行,以便画廊中没有空白区域。
这对我来说是个棘手的问题,我对 Objective-C 还是很陌生,不知道该怎么做。我知道我可能应该调用moveRowAtIndexPath 和toIndexPath,但我不确定是否应该在viewDidLoad、viewWillAppear 中执行此操作,还是应该为此创建自己的方法?这是我正在使用的示例,可能相关也可能不相关:
- (void)applicationDidEnterBackground:(UIApplication*)application {
NSLog(@"Image on didenterbackground: %@", imageView);
NSMutableArray* array = [NSMutableArray arrayWithObject:[NSData dataWithData:UIImagePNGRepresentation(imageView.image)]];
[array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView2.image)]];
[array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView3.image)]];
[array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView4.image)]];
[self.user setObject:array forKey:@"images"];
[user synchronize];
}
- (void)viewDidLoad
{
self.user = [NSUserDefaults standardUserDefaults];
NSLog(@"It is %@", self.user);
NSMutableArray* array = [[self.user objectForKey:@"images"]mutableCopy];
imageView.image = [[UIImage alloc] initWithData:[array objectAtIndex:0]];
imageView2.image = [[UIImage alloc] initWithData:[array objectAtIndex:1]];
imageView3.image = [[UIImage alloc] initWithData:[array objectAtIndex:2]];
imageView4.image = [[UIImage alloc] initWithData:[array objectAtIndex:3]];
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:app];
backToGalleryButton.hidden = YES;
tapToDeleteLabel.hidden = YES;
deleteButton1.hidden = YES;
[super viewDidLoad];
}
非常感谢您对此提供任何帮助或建议,谢谢!
【问题讨论】:
-
这些图像视图是表格视图吗?
-
不,我不是,我应该有,但我有点太过分了,也回头了。不过如果有必要我会的。
标签: objective-c ios uiimageview nsmutablearray