I make tableView
and collectionView
in my ViewController
and was set the Delegate and DataSource to my ViewController
with extension or include the class.
The cell already show correctly on both of them, I haven't any UITapGestureRecognizer
in my Class but when I want to tap on my Cell the didSelectRowAt
not called.
I've added canEditRowAt
and It's work but not with didSelectRowAt
This is my ViewController Scene
My TableView already set :
- UserInteractionEnable = true
- Selection = Single Selection
My Xib Files :
- UserInteractionEnable = true
This is my class :
class ProfileVC: UIViewController {
@IBOutlet weak var profileTableView: UITableView!
var profileTitle = DataService.instance.profileTitle
override func viewDidLoad() {
super.viewDidLoad()
configureTableView()
}
func configureTableView() {
let nib = UINib(nibName: "ProfileCell", bundle: nil)
profileTableView.register(nib, forCellReuseIdentifier: "ProfileCell")
profileTableView.delegate = self
profileTableView.dataSource = self
profileTableView.allowsSelection = true
}
}
extension ProfileVC: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return profileTitle.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileCell", for: indexPath) as? ProfileCell else { return ProfileCell() }
cell.configureCell(withTitle: profileTitle[indexPath.row])
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("Selected")
}
}
This is my ProfileCellClass :
class ProfileCell: UITableViewCell {
@IBOutlet weak var titleLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
func configureCell(withTitle title: String){
self.titleLabel.text = title
}
}
Thank you.