Ich habe TableView
, wo Benutzer klicken und erweitern Sie jede Zelle (UI: click). Dies ist der Code für das (auch habe ich .xib
Datei diese Zelle Layout):Erweiterte und Swipe-fähige Zelle in TableView
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchResultsUpdating {
var selectedIndex: IndexPath?
var isExpended = false
func didExpandCell() {
self.isExpended = !isExpended
self.tableView.reloadRows(at: [selectedIndex!], with: .automatic)
}
@IBOutlet weak var tableView: UITableView!
...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "wordCell", for: indexPath) as! CellController
if searchController.isActive {
cell.word.text = filtered[indexPath.row].word
cell.translation.text = filtered[indexPath.row].translation
cell.date.text = filtered[indexPath.row].fullDate
cell.exOne.text = filtered[indexPath.row].exOne
cell.exTwo.text = filtered[indexPath.row].exTwo
} else {
cell.word.text = words[indexPath.row].word
cell.translation.text = words[indexPath.row].translation
cell.date.text = words[indexPath.row].fullDate
cell.exOne.text = words[indexPath.row].exOne
cell.exTwo.text = words[indexPath.row].exTwo
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.selectedIndex = indexPath
self.didExpandCell()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if isExpended && self.selectedIndex == indexPath {
return 180
}
return 70
}
}
Auch alle Zellen werden Swipe-able. Dies ist der Code:
func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
let edit = UITableViewRowAction(style: .normal, title: "Edit") { action, index in
print("Edit")
}
edit.backgroundColor = .blue
let delete = UITableViewRowAction(style: .normal, title: "Delete") { action, index in
print("Delete")
}
delete.backgroundColor = .red
return [delete, edit]
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
Das Problem:
Wenn ich Handy Swipe, es aufwendet immer in einer Hälfte, das ist meine UI nach klauen: click. Ist es möglich, Cell nicht zu erweitern, wenn ich sie wische?
Können Sie einen Debug-Punkt in didSelectRowAt-Methode setzen und sehen, wenn Sie wischen, wird dies aufgerufen? – 3stud1ant3
ist Ihre Erweiterungsfunktion nicht fehlerhaft, func didExpandCell()? Sagen wir, wenn ich auf Zelle1 klicke, isExpended = true und es öffnet Cell. Wenn ich erneut auf Zelle2 klicke, wird isexpended = false gesetzt und Cell2 nicht erweitert. –
Nein, es ist nicht auf Swipe –