Я студент, пытающийся изучать программирование на iOS, и столкнулся с некоторыми проблемами.Я пытаюсь добавить кнопку-флажок в свой пользовательский UITableViewCell и позволить ему удалить ячейку при нажатии.Однако, хотя я могу добавить кнопку, и она может быть нажата, ничего не происходит.UITableViewCell все еще там.Как я могу это исправить?
Это мой пользовательский класс ячеек:
import UIKit
class ClientCell: UITableViewCell {
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var clientImageView: UIImageView!
@IBAction func checkBoxTapped(_ sender: UIButton) {
if sender.isSelected == true {
sender.isSelected = false
} else {
sender.isSelected = true
}
}
}
Это ViewController, который содержит UITableView:
import UIKit
import CoreData
class ClientsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Client")
var clients = [NSManagedObject]()
@IBOutlet weak var clientTable: UITableView!
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return clients.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ClientCell
cell.label.text = clients[indexPath.row].value(forKey: "name") as? String
cell.clientImageView.layer.cornerRadius = 12
return(cell)
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCell.EditingStyle.delete {
CDHandler.deleteObject(indexPath: indexPath)
clients.remove(at: indexPath.row)
clientTable.reloadData()
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
if CDHandler.fetchObject() != nil {
clients = CDHandler.fetchObject()!
}
clientTable.reloadData()
}
}
Любая помощь оченьоценили!Спасибо!