私はUITableView
を持っており、UILongPressGestureRecognizer
を実装しました。セルを長押しすると、handleLongPress
という関数が呼び出されます。AnyObjectセルのタイプをチェックする方法は?
func handleLongPress(sender:AnyObject){
}
問題があり、UITableView
はので、私は長いクリックするcell
の種類を知っておく必要があり、私の中UITableViewCells
にはいくつかの種類があります。私のカスタムセルの例:
if sender is ProfileTableViewCell{
print("Long Clicked!")
}
そして、この:これらの作業の
if let mType = sender as? ProfileTableViewCell{
print("Long Clicked!")
}
なし
import UIKit
class ProfileTableViewCell: UITableViewCell {
@IBOutlet weak var ivProfile: UIImageView!
@IBOutlet weak var tvName: UILabel!
@IBOutlet weak var tvEmail: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
は、私はこれを試してみました。どのように細胞のタイプをチェックするのですか?
編集:これは、ジェスチャー認識を割り当てる方法です:
let cell = tableView.dequeueReusableCellWithIdentifier("profileCell", forIndexPath: indexPath) as! ProfileTableViewCell
longPress = UILongPressGestureRecognizer(target: self, action: #selector(ProfileTableViewController.handleLongPress(_:)))
longPress.minimumPressDuration = 0.5
longPress.delaysTouchesBegan = true
longPress.delegate = self
cell.addGestureRecognizer(longPress)
どのようにジェスチャー認識を割り当てていますか? – xoudini
私は編集として追加しました。 –
さて、あなたが 'UITableViewCell'のサブクラスだけを送信者にすることを期待しているならば、' sender:AnyObject'を 'sender:UITableViewCell'に変更することができます。 – xoudini