構造体を使用して、セクションと行を持つテーブルビューコントローラを作成しています。今私はテーブルからセルを削除する必要があります。それを削除するには、リスト内の要素をどのように見つけることができますか?Swift 3:構造体の配列内のインデックスを検索し、配列からアイテムを削除します。
構造体:
struct Cells {
var section: String!
var list: [String]!
}
セクションと行
var tableStructure = [Cells(section: "Requests", list: ["uidU", "uidV"])]
コード、構造体に私は、リストから削除する要素を検索するための構造体のリストから項目を削除し、その後、セルを削除するには
let index = tableStructure.index(where: {$0.section == "Requests" && list.index{$0 == cell.selectedUserUid} as Any as! Bool})
self.tableStructure.remove(at: index!) //***ERROR HERE***
tableView.deleteRows(at: [indexPath], with: .fade)
エラーメッセージ::テーブルビューから
fatal error: unexpectedly found nil while unwrapping an Optional value
"cell.selectedUserUid"の内容を見るためにブレークポイントを設定しました。これはstructから削除したい要素と同じです。
提案?ありがとう!
ありがとうございました。私はコードを変更し、コードを使用してアイテムを削除しました。 if let indexStructSection = tableStructure.index(where:{($ 0?.section == "Requests")}){ tableStructure [indexStructSection] ?. list = tableStructure [ indexStructSection]?list?.filter(){$ 0!= cell.selectedUserUid} } – Enzo