我正在开发一个类似于照片库的应用程序,并且正在实施让用户从其图库中删除照片的选项。为了做到这一点,我决定在每张照片上放置一个隐形按钮。当用户点击“编辑”按钮时,每个图片上的隐藏删除按钮变为活动状态。为了简单起见,我在每个隐藏按钮上使用了相同的IBOutlet,并且我在Interface Builder中适当地标记了每个按钮。当用户点击图片上的按钮时,会出现一个警告视图,询问他们是否真的要删除它。如果他们点击是,我调用removeObjectAtIndex。这里是我使用的代码:从UI中删除图像
- (IBAction)deleteButtonPressed:(id)sender {
NSLog(@"Sender is %@", sender);
UIAlertView *deleteAlertView = [[UIAlertView alloc] initWithTitle:@"Delete"
message:@"Are you sure you want to delete this photo?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
[deleteAlertView show];
int imageIndex = ((UIButton *)sender).tag;
deleteAlertView.tag = imageIndex;
}
- (void)alertView: (UIAlertView *) alertView
clickedButtonAtIndex: (NSInteger) buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex]) {
NSLog(@"User Clicked Yes. Deleting index %d of %d", alertView.tag, [array count]);
[self.array removeObjectAtIndex: alertView.tag];
NSLog(@"After deleting item, array count = %d", [array count]);
alertView.tag.image = nil;
}
[self.user setObject:self.array forKey:@"images"];
}
这里的问题是alertView.tag.image
。我有一个错误,指出“成员引用基类型NSInteger(aka int)不是一个结构或联合。这段代码删除阵列中的图像很好,但我仍然需要从UI中删除图像。 alertView.tag.image
就可以做到这一点,我不知道如何做到这一点,我对Objective-C仍然很陌生,我读的这本书根本没有涉及到这一点,我也想知道如何刷新UI ?删除图像后
非常感谢您的回答,尽管当我添加代码时Xcode声明在'UIView *'类型的对象上找不到'Property'image。 – John 2012-04-04 16:01:47
将它转换为(UIImageView *)。让我编辑它 – Vignesh 2012-04-04 16:03:58
真棒,谢谢你的帮助! – John 2012-04-04 16:09:30