我正在實施一個滑動刪除UiTableView的行動,我創建了一個表,它工作正常。但是當我點擊表格視圖中的項目時didSelectRowAt
未被調用 - 它不打印日誌。UiTableView didSelectRowAt方法不叫
代碼
class ManageUsersTable: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var editView: UIView!
@IBOutlet weak var main_user_table: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
editView.isHidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Bundle.main.loadNibNamed("UsersTableCell", owner: self, options: nil)?.first as! UsersTableCell
cell.selectionStyle = UITableViewCellSelectionStyle.none
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("selected : \(indexPath.row)")
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
print("Delete at index : \(indexPath.row)")
let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
// delete item at indexPath
print("Delete at index : \(indexPath.row)")
self.editView.isHidden = false
}
// let edir = UITableViewRowAction(style: .normal, title: "Edit", icon : UIImage()) { (action, indexPath) in
// print("Edit at index : \(indexPath.row)")
// }
// edit.backgroundColor = UIColor.darkGray
// return [delete, edit]
return [delete]
}
}
能有人幫我解決這個問題TNX。
更新
當我刷卡由左到右的方法工作。不在物品上點擊
有你設置的tableview委託ManageUsersTable在其情節提要/筆尖? –
是的。我已經設置了代理 –
驗證'userInteractionEnabled'屬性一次。 – Buntylm