私はcollectionViews
とTableViews
を使って作業していますが、これはちょっと混乱します。私はコレクションビューをViewController
と一緒にデリゲートとデータソース自身にセットしています。しかし、didSelectItemAtIndexPathを使用しようとすると、何も起こりません。コレクションも完全に表示され、データソース関数がうまく機能しています。コレクションビューSwiftでアイテムを選択できません
これは私のコードです:
@IBOutlet weak var timeCollectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
//Register the Cell
let nib = UINib(nibName: "DurationSelectionCollectionViewCell", bundle:nil)
self.timeCollectionView.registerNib(nib, forCellWithReuseIdentifier: "DurationSelectionCollectionViewCell")
timeCollectionView.delegate = self
timeCollectionView.dataSource = self
....
}
//Selecting an item and highlighting it.
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
timeCollectionView.cellForItemAtIndexPath(indexPath)?.backgroundColor = UIColor.grayColor()
}
私はそれを試しただけで何も起こっていません! didSelectItemAtIndexPathItemにブレークポイントの場所があり、セルのいずれかをクリックすると、関数がコールを受け取ったことを示すフィードバックが表示されません。 – Gugulethu