Я делаю tableView
и collectionView
в моем ViewController
, и для делегата и источника данных был установлен мой ViewController
с расширением или включением класса.
Ячейка уже отображается правильно на обоих из них, у меня нет никаких UITapGestureRecognizer
в моем классе, но когда я хочу нажать на свою ячейку, didSelectRowAt
не вызывается.
I добавили canEditRowAt
и это работает, но не с didSelectRowAt
Это моя сцена ViewController
Мой TableView уже установлен:
- UserInteractionEnable = true
- Selection = Single Selection
Мои файлы Xib:
- UserInteractionEnable = true
Это мой класс:
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")
}
}
Это мой 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
}
}
Это мой файл .xib
Спасибо.