长按 select 下拉菜单中的一个选项
Long press to select an option from a dropdown menu
我必须长按 select 才能从下拉菜单中选择一个选项。我希望 selection 立即生效。我该如何解决这个问题。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = UITableViewCell()
cell = countryTableView.dequeueReusableCell(withIdentifier: "countryCell", for: indexPath)
cell.textLabel?.text = country[indexPath.row]
return cell
}
您是否尝试过实现 UITableViewDelegate 函数?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
我在这个 link 中找到了解决方案:
didSelectRowAtIndexPath not being called
是否有 UITapestureRecognizer
您是否在 table 视图之上创建了 UITapGestureRecognizer?
UITapGestureRecognizer 可能在您的点击事件到达您的 table 视图之前吞噬了它们。
要解决此问题,请将 UITapGestureRecognizer 的 cancelsTouchesInView 属性 设置为 false。
您还可以通过选择 UITapGestureRecognizer、导航到 属性 检查器并取消选中此框来在故事板中进行设置:
我必须长按 select 才能从下拉菜单中选择一个选项。我希望 selection 立即生效。我该如何解决这个问题。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = UITableViewCell()
cell = countryTableView.dequeueReusableCell(withIdentifier: "countryCell", for: indexPath)
cell.textLabel?.text = country[indexPath.row]
return cell
}
您是否尝试过实现 UITableViewDelegate 函数?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
我在这个 link 中找到了解决方案:
didSelectRowAtIndexPath not being called
是否有 UITapestureRecognizer 您是否在 table 视图之上创建了 UITapGestureRecognizer?
UITapGestureRecognizer 可能在您的点击事件到达您的 table 视图之前吞噬了它们。
要解决此问题,请将 UITapGestureRecognizer 的 cancelsTouchesInView 属性 设置为 false。
您还可以通过选择 UITapGestureRecognizer、导航到 属性 检查器并取消选中此框来在故事板中进行设置: