【问题标题】:scroll to top searchbarcontroller when clicked on tableview cell单击 tableview 单元格时滚动到顶部搜索栏控制器
【发布时间】:2018-04-18 11:16:44
【问题描述】:

当我写文本时,searchController 移到顶部,但是当我单击 tableview 单元格时,我想要相同的行为。 searchController 需要将其设置为在 appstore 应用程序上的工作。如下所示,我点击 tableview 单元格,所以我希望 searchController 移到顶部。所以我必须在我的代码中写什么。谢谢

【问题讨论】:

    标签: ios tableview uinavigationitem uisearchcontroller


    【解决方案1】:

    使UISearchBar 中的UITextField 成为您点击单元格时的第一响应者()。

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
    
            if let searchField = searchController.searchBar.value(forKey: "searchField") as? UITextField {
                searchField.becomeFirstResponder()
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 2010-11-06
      • 2012-02-28
      • 1970-01-01
      • 2015-07-18
      相关资源
      最近更新 更多