我正在尝试允许用户在我的收藏夹视图中进行交互。我决定尝试实现UITapGestureRecognizer来执行此操作。我尝试将UITapGestureRecognizer添加到collectionview本身以及collectionview单元中。两种方法都会使应用程序崩溃。这是我将UITapGestureRecognizer添加到单元格的方式。
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionview.dequeueReusableCell(withReuseIdentifier: "userCell",for: indexPath) as! UserCell
cell.userImage.sd_setImage(with: URL(string: self.user[indexPath.row].imagePath))
cell.nameLabel.text = self.user[indexPath.row].username
cell.userID = self.user[indexPath.row].userID
let singletap: UITapGestureRecognizer = UITapGestureRecognizer(target: self,action: "segueToProfile:")
singletap.numberOfTapsRequired = 1
singletap.numberOfTouchesRequired = 1
cell.addGestureRecognizer(singletap)
return cell
}
当我点击单元格时,在AppDelegate中会得到一个SIGABRT。错误消息显示为“以类型为NSException的未捕获异常终止”。我究竟做错了什么。 UITapGestureRecognizer。
这是我的segueToProfile函数:
func segueToProfile(gesture: UITapGestureRecognizer) {
// if(recognizer.state == UIGestureRecognizer.State.ended){
// print("myUIImageView has been tapped by the user.")
// }
print("hell world")
}