そのため、フォトギャラリーのように動作するアプリがあり、ユーザーが画像を削除する機能を実装しています。設定は次のとおりです。9つのUIImageView、imageView、imageView2などがあります。[編集]ボタンとtapGestureアクションメソッドもあります。Tap Gesture RecognizerをIBのビューにドラッグし、UIImageViewのそれぞれにアタッチしました。また、各UIImageViewにtapGestureアクションメソッドをアタッチしました。理想的には、「編集」ボタンが押されたときにのみメソッドがアクティブになるようにしたいです。ユーザーが[編集]をタップしてから、削除する画像をタップすると、UIAlertViewが表示され、削除してもよいかどうかを尋ねられます。これが私が使用しているコードです:
- (IBAction)editButtonPressed:(id)sender {
editButton.hidden = YES;
backToGalleryButton.hidden = NO;
tapToDeleteLabel.hidden = NO;
}
- (IBAction)tapGesture:(UITapGestureRecognizer*)gesture
{
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];
if (buttonIndex != [alertView cancelButtonIndex]) {
UIImageView *view = [self.UIImageView];
if (view) {
[self.array removeObject:view];
}
CGPoint tapLocation = [gesture locationInView: self.view];
for (UIImageView *imageView in self.view.subviews) {
if (CGRectContainsPoint(self.UIImageView.frame, tapLocation)) {
((UIImageView *)[self.view]).image =nil;
}
}
[self.user setObject:self.array forKey:@"images"];
}
}
このコードは明らかにエラーでいっぱいです:この行の「宣言されていない識別子ボタンインデックスの使用」:if (buttonIndex != [alertView cancelButtonIndex])
この行の「タイプPhotoViewControllerのオブジェクトにプロパティUIImageViewが見つかりません」UIImageView *view = [self.UIImageView];
そして、この行の「期待される識別子」((UIImageView *)[self.view]).image =nil;
私はプログラミングに非常に慣れていないので、ここまでやってきたことに驚いています。したがって、エラーがなくなり、9つの画像ビューのいずれかがタップされたときにいつでも使用できるようにコードを編集する必要がある方法を理解しようとしています。また、このメソッドは、編集ボタンが最初に押されます。以前はタグを使用していましたが、うまく機能しましたが、NSDataを介して画像を保存しているため、タグを使用できなくなりました。どんな助けでも大歓迎です、ありがとう!