【发布时间】:2018-05-09 10:19:13
【问题描述】:
我在我的ViewController 中创建了tableView 和collectionView,并将Delegate 和DataSource 设置为我的ViewController,并带有扩展名或包含该类。
单元格已经正确显示在他们两个上,我的班级中没有任何 UITapGestureRecognizer,但是当我想点击我的单元格时,didSelectRowAt 没有被调用。
我'已添加 canEditRowAt 并且它可以工作,但不适用于 didSelectRowAt
This is my ViewController Scene
我的 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
}
}
谢谢。
【问题讨论】:
-
你在哪里添加
profileTableView?你能滚动它吗? -
在 viewDidLoad() 中,当我滚动 UITableView 或 UICollectionView 时,它会弹跳
-
你能否尝试实现另一个 UITableView 委托方法(如
estimatedHeightForRowAt)并确保它被调用? -
您没有 IBOutlet 甚至没有 profileTableView 的实例变量?
标签: ios swift uitableview uicollectionviewcell uitableviewrowaction