- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有带有嵌入式 UICollectionView 的 UITableView。在第一部分中,有带有 UITextField 的自定义单元格,在第二部分中有 UICollectionView。
当用户点击我正在使用的 UITextField 外部时隐藏键盘
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
view.addGestureRecognizer(tap)
func dismissKeyboard(sender: UIGestureRecognizer) {
view.endEditing(true)
}
正因为如此,正如我所发现的,我的 UICollectionView 无法识别其项目上的点击。如果我删除 view.addGestureRecognizer(tap) 一切正常,但键盘在这种情况下不会隐藏。
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder() //if desired
return true
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileTableViewCell", for: indexPath) as! ProfileTableViewCell
cell.value.delegate = self // value is my textField
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: "WallpaperTableViewCell", for: indexPath) as! WallpaperTableViewCell
cell.setCollectionViewDataSourceDelegate(dataSourceDelegate: self, index: (indexPath as NSIndexPath).row)
return cell
default:
let cell = UITableViewCell()
return cell
}
}
如何解决此问题并在 UICollectionView 中同时使用隐藏键盘和点击识别?谢谢
为了将 UICollectionView 嵌入到 UITableView 中,我使用了这个示例 https://github.com/DahanHu/DHCollectionTableView
UPD
感谢菲利普·米尔斯
答案非常简单
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
和
func keyboardWillShow(notification: NSNotification) {
view.addGestureRecognizer(tap)
}
func keyboardWillHide(notification: NSNotification) {
view.removeGestureRecognizer(tap)
}
最佳答案
仅在键盘出现时添加手势识别器,并在键盘消失时将其删除。
关于swift - UITableView 中的 UICollectionView 由于 view.addGestureRecognizer() 未检测到点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40726905/
我正在制作一个应用程序来计算距离和面积,现在问题是我制作了一个数组并在其中附加了我的节点。 func calculate () { let start = dotNodes[0] le
在我的 Eclipse 上,双分隔符使用逗号而不是点,我想将其更改为逗号,但我不知道如何更改。代码本身如下: double latitudeBerlin = 52.51217; double long
我想知道,如果: string name_a; string name_b; 将有一些已经存在的函数可以让我比较两个字符串的一定数量的字符like strncmp() ,但来 self 的 strin
我在 X 轴上有点,我想从每个点到另一个点 (X2,Y2) 做直线。 此代码适用于从 Y=35 到 X 点 (P) 的蓝线,并且它有效 pos_fixed = np.array([0, TR]) li
我必须返回以度为单位的角度,它应该在 0 到 360(含)之间的范围内。我必须使用 math.h 库中的函数 acos()、asin() 和 atan()。在我的说明中,它说根据该点所在的象限,计算可
请考虑以下说明我的问题的简化示例: 主窗口.xaml 主窗口.xaml.cs using System; using System.Windows; using System.Windo
我是一名优秀的程序员,十分优秀!