gpt4 book ai didi

ios - UITableViewCell didSelectRowAtIndexPath 在响应选择时非常慢

转载 作者:行者123 更新时间:2023-11-28 15:56:37 24 4
gpt4 key购买 nike

我想要的只是快速点击单元格以启动新 View 。发射有效,但需要很长时间(3-5 秒)按住单元格才能注册它已被选中。这是正常行为吗?我找不到任何方法来响应简单的 .touchUpInside 事件。那我做错了什么?我已经浏览了 UITableViewCell 的 Apple 文档,但找不到任何对我有帮助的字段或设置。提前致谢!

编辑:在 View Controller viewDidLoad:

self.searchTable.dataSource = self
self.searchTable.delegate = self
self.searchTable.register(UINib(nibName: "ItemCellView", bundle: nil), forCellReuseIdentifier: "itemCell")
self.searchTable.reloadData()

在 View Controller 中:

func searchBarSearchButtonClicked(_ searchBar: UISearchBar){
searchItems.removeAll()
self.searchBar.endEditing(true)
requests.requestSearch(query: searchBar.text!, filter: "RATING", vc: self)
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (self.searchItems.count)
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.searchTable.dequeueReusableCell(withIdentifier: "itemCell")! as! ItemCell
cell.formatCell(item: self.searchItems[indexPath.row])

return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
let item = self.searchItems[indexPath.row]
let vc = self.storyboard?.instantiateViewController(withIdentifier: "item") as? ItemController
vc?.item = item
self.navigationController?.pushViewController(vc!, animated: false)
}

编辑#2:

我还想说明一点,我的代码中根本没有任何 GestureRecognizers。

最佳答案

想通了。虽然我没有直接向该文件添加任何手势识别器,但我是通过使用我制作的一个功能间接添加的,该功能允许我轻敲键盘使它们消失。我所要做的就是将这一行代码添加到该函数中,它现在可以完美运行了。感谢@mat 的帮助!

罪魁祸首

extension UIViewController {
func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
}

func dismissKeyboard() {
view.endEditing(true)
}

关于ios - UITableViewCell didSelectRowAtIndexPath 在响应选择时非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41643600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com