2016-10-14 2 views
0

Actuellement, j'essaie d'ajouter un geste de balayage vers le haut et vers le bas aux cellules de mon UICollectionView pour effectuer des actions spécifiques. J'ai fait tout cela par programme, mais je reçois sigabrt. Aucune suggestion?Sigabrt Error- UIGestureRecognizer par programme

class TableViewCell: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate { 

    var collectionView: UICollectionView! 
    var cellTextLabel: UILabel! 




    override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
     super.init(style: style, reuseIdentifier: reuseIdentifier) 


     let layout = UICollectionViewFlowLayout() 
     layout.scrollDirection = UICollectionViewScrollDirection.horizontal 
     layout.itemSize = CGSize(width: 90, height: 90) 
     collectionView = UICollectionView(frame: self.bounds, collectionViewLayout: layout) 

     collectionView.delegate = self 
     collectionView.dataSource = self 
     collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "CollectionViewCell") 

     collectionView.backgroundColor = UIColor(red: 34.0/255.0, green: 40.0/255.0, blue: 51.0/255.0, alpha: 1.0) 
     collectionView.frame.size.height = 120 
     collectionView.frame.size.width = 500 
     self.addSubview(collectionView) 


    } 

    required init(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder)! 
    } 

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 
     return 1 
    } 


    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     return 10 
    } 

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 




     var arrayOfReviewVocab = ["衣服" + "\n" + "clothes", "学校" + "\n" + "school", "你好" + "\n" + "hello", "书" + "\n" + "books", "5", "6", "7", "8", "9", "10"] 

     let cell: UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! UICollectionViewCell 

     cell.backgroundColor = UIColor(red: 30.0/255.0, green: 35.0/255.0, blue: 46.0/255.0, alpha: 1.0) 

     cellTextLabel = UILabel(frame: CGRect(x: 20 , y: -20, width: frame.size.width, height: frame.size.height)) 
     cell.contentView.addSubview(cellTextLabel!) 
     cellTextLabel.textColor = UIColor.white 
     cellTextLabel.text = arrayOfReviewVocab[indexPath.row] 
     cellTextLabel.numberOfLines = 0 

     var swipeUp = UISwipeGestureRecognizer(target: cell, action: "handleSwipeGesture:") 
     swipeUp.direction = .up 
     cell.addGestureRecognizer(swipeUp) 

     var swipeDown = UISwipeGestureRecognizer(target: cell, action: "handleSwipeGesture:") 
     swipeDown.direction = UISwipeGestureRecognizerDirection.down 
     cell.addGestureRecognizer(swipeDown) 
     return cell 
    } 

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 
     return CGSize(width: 200, height: 200); 
    } 



    func handleSwipeGesture(gesture: UISwipeGestureRecognizer) 
    { 


     if(gesture.direction == .up) 
     { 
      print("up") 
     } 

     if (gesture.direction == .down) 
     { 
      print("down") 
     } 

    } 

} 

Voici le message d'erreur:

[UICollectionViewCell handleSwipeGesture:]: unrecognized selector sent to instance 0x7fd2fb61ee20 
+0

mettez à jour votre question avec un seul écran. –

Répondre

0

Vous devez définir la cible: l'auto non cible: cellule si la méthode handleSwipeGesture: est en classe TableViewCell

var swipeDown = UISwipeGestureRecognizer(target: self, action: "handleSwipeGesture:") 
0
var swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(self. handleSwipeGesture)) 
swipeleft.direction = .Up 
cell!.addGestureRecognizer(swipeUp) 

même comme pour Down.

Codage heureux.

+0

Toujours en cours. J'ai ajouté le message d'erreur ci-dessus –

+0

@VikramSeshadri avez-vous utilisé le même code que je vous dis? s'il vous plaît mettre à jour votre question avec le mien –