ios - didSelectRowAt indexPath 未被调用

标签 ios iphone swift uitableview swift3

我创建了一个包含两个 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。

问题是没有一个 tableViews 单元调用 didSelectRowAt。 enter image description here

最佳答案

如果您将按钮添加到单元格,则在点击按钮时不会调用 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/

相关文章:

ios - 推送新 View Controller 时最后一个 Controller 的内容可见

ios - 为什么我不能用自定义 UIColor 填充 UIBezierPath?

ios - Facebook 应用程序链接如何在不声明 LSApplicationQueriesSchemes 的情况下工作?

ios - 多次调用一个 Alamofire 请求,获取每次调用的引用

ios - 如何解决此错误 : "Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)"?

ios - 在 icloud 上禁用文档文件夹及其所有子文件夹的备份?

iphone - 如何将预填充的 SQLite 数据库集成到 PhoneGap iPhone 应用程序中

ios - TableView Load More 正在不停地获取

ios - Snap Kit 不使用 startSending 打开 Snapchat

swift - 在 Swift 中 5 秒后跳出 while 循环