I’m working on an app that behaves like a photo gallery, and I’m implementing the option to have the user delete photos from their gallery. To accomplish this, I decided to place an invisible button over each picture. When the user hits an “Edit” button, the hidden delete buttons over each picture become active. I’m using the same IBOutlet over each of the hidden buttons for simplicity, and I’ve tagged each button appropriately in Interface Builder. When the user taps the button over the picture, an alert view appears asking if they really want to delete it. If they click yes, I call removeObjectAtIndex. Here is the code I’m using:
- (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"];
}
The issue here is alertView.tag.image. I have an error stating “Member reference base type NSInteger (aka int) is not a structure or union. This code deletes the image out of the array just fine, but I still need to delete the image from the UI as well. I thought that alertView.tag.image would have done the trick. I have no idea how to do this, I’m still new to Objective-C and the book I read does not cover any of this at all. I was also wondering how I could refresh the UI after deleting the image?
tag is just NSInteger. It doesn have property called image. You should use,