我创建了一个包含两个 View (顶部、底部)的 UIViewController, 单击搜索栏时,底部 View 会一直扩展到顶部。 (bottomView 高度扩大,topView 高度变小)。
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
self.expandBottomView()
return true
}
func expandBottomView() {
let heightToAdd = TopView.frame.height - numOfRequestsTitle.frame.height
RecomandFriendHeight.constant += heightToAdd
UIView.animate(withDuration: 0.5) {
self.view.layoutIfNeeded()
}
topTableView.isUserInteractionEnabled = false
}
两个 View 都包含 TableView(topTableView、BottomTableView),我检查了所有委托(delegate)。 BottomView 包含另一个按钮,可在需要时折叠 bottomView。
topTableViewCell 包含两个按钮和两个标签。 bottomTableViewCell 包含一个标签和一个 imageView。
最佳答案
如果您将按钮添加到单元格,则在点击按钮时不会调用 didSelectAt。在这种情况下,您必须向 cellForRowAt 中的此按钮添加一个选择器:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! customcell
cell.btn.addTarget(self, action: #selector(clickedCell), for: .touchUpInside)
return cell
}
并实现这个选择器方法
func clickedCell(_ sender : UIButton) {
print("clicked")
}
关于ios - didSelectRowAt indexPath 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44562702/