Derzeit versuche ich eine Wischgeste nach oben und unten zu Zellen in meiner UICollectionView hinzufügen, um bestimmte Aktionen durchzuführen. Ich habe das alles programmatisch gemacht, aber ich werde sigabrt. Irgendwelche Vorschläge? HierSigabrt Error-UIGestureRecognizer programmatisch
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")
}
}
}
ist die Fehlermeldung:
[UICollectionViewCell handleSwipeGesture:]: unrecognized selector sent to instance 0x7fd2fb61ee20
aktualisieren Sie Ihre Frage mit einem Bildschirm. –