I have added a delete on swipe in a list:
.onDelete(perform: deleteBook)
private func deleteBook(at offsets: IndexSet) {
offsets.forEach { index in
let book = books[index]
let bookData = BookData(
bookID: book.bookID ?? "",
isbn: book.isbn ?? "",
title: book.title ?? "",
subtitle: book.subtitle ?? "",
authors: book.authors ?? "",
description: book.bookDescription ?? "",
publishedDate: book.publishedDate ?? "",
publisher: book.publisher ?? "",
language: book.language ?? "",
thumbnailURL: book.thumbnailURL ?? "",
tags: [book.tag1, book.tag2, book.tag3].compactMap { $0 },
borrowCounter: Int(book.borrowCounter)
)
bookToRestore = bookData
databaseManager.deleteBook(book) { success in
DispatchQueue.main.async {
if success {
books.remove(at: index)
showToast = true
}
}
}
}
}
This worked without any problems. Afterwards I added a hidekeyboard function in the view, since then the delete on swipe no longer works properly.
.simultaneousGesture(TapGesture().onEnded {
hideKeyboard()
private func hideKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
The .simultaneousGesture(TapGesture().onEnded of the hidekeyboard is applied to the entire list.
If I swipe all the way to the left, the entry is still deleted. However, if I only swipe a little so that the delete button appears, the button does not work. As soon as I comment out the hidekeyboard, everything works again. Can anyone help me with the reason for this?