我正在尝试在UITableView的viewForHeaderInSection
中添加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**....//
}
我可以看到该应用在Simulator上运行良好,并且可以运行TapGesture View。该应用程序还可以在iPhone 8和iOS 11.0中运行
但是我尝试在具有iOS> 11.2的iPhone SE或iPhone 8上运行该应用程序,由于'tapGesture.view?.tag'为nil,应用程序崩溃了
请提出我在做什么错