ios - 点击手势的值为 nil
问题描述
我正在尝试在viewForHeaderInSection
UITableView 中添加 TapGuesture。下面是中的代码
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if !isFromSearchBarData {
let headerView = CategoryHeaderView(frame: CGRect(x:0.0, y:0.0, width: tableView.frame.size.width, height: 50.0))
headerView.viewDictModel = arrayOfCategoryDictionary[section].values.first
headerView.tag = section
//Add Tap
let headerTapped = UITapGestureRecognizer (target: self, action:#selector(sectionHeaderTapped(tapGesture:)))
headerTapped.numberOfTapsRequired = 1
headerView .addGestureRecognizer(headerTapped)
return headerView
}
else {
return nil
}
}
现在行动在下面
@objc func sectionHeaderTapped(tapGesture : UITapGestureRecognizer) {
//...some code...//
print("Item is :\(String(describing: tapGesture.view?.tag))")
//SOme Code on **Tag**....//
}
我可以看到该应用程序在模拟器上运行良好,并且我可以让 TapGesture View 运行起来。应用程序也适用于带有 iOS 11.0 的 iPhone 8 plus
但我尝试在 iOS > 11.2 的 iPhone SE 或 iPhone 8 上运行该应用程序,由于 'tapGesture.view?.tag' 为 nil,应用程序崩溃
请建议我做错了什么。
解决方案
推荐阅读
- javascript - 我的搜索似乎无法弄清楚。我的情况是字符串和数组的问题
- html - 如何使图像自动调整大小以适合之间有边距的线?
- java - 满足某些条件时如何执行 button.setOnTouchListener (Kotlin)
- c# - 使用 HttpClient 或其他 C# 类发送带有密钥库文件的肥皂请求
- sql - PostgreSQL 索引减少了数据大小但使查询变慢
- php - 服务器移动后TYPO3 argon2密码哈希匹配部分不匹配
- r - 在导入之前过滤 CSV 文件以获取特定值
- javascript - Discord.js 用户状态自定义
- postgresql - Postgres 动态过滤条件
- php - 数组中的 if else 条件