【发布时间】:2017-10-05 08:23:01
【问题描述】:
我正在为 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属性一次。 -
你确定你的tableview选择是单选的吗?和编辑呢
-
你为编辑设置了什么?
标签: ios uitableview swift3