これは簡単な質問で、答えは見つけやすいと思いましたが、そうではありませんでした。コレクションビューでセルを選択したい。主な問題は、ジェスチャレコグナイザーをプロトタイプセルに接続できないことです。タッチしたセルのラベルからテキストを取得したい。私の見解では、別の関数でこの名前を使用しています。
またはもっと簡単な質問:アイテムのリストからのタップ選択に関するチュートリアルはありますか?
これは簡単な質問で、答えは見つけやすいと思いましたが、そうではありませんでした。コレクションビューでセルを選択したい。主な問題は、ジェスチャレコグナイザーをプロトタイプセルに接続できないことです。タッチしたセルのラベルからテキストを取得したい。私の見解では、別の関数でこの名前を使用しています。
またはもっと簡単な質問:アイテムのリストからのタップ選択に関するチュートリアルはありますか?
collectionView:didSelectItemAtIndexPath:
デリゲートにメソッドがあります。これは、セルを収集し、その特定のセルの正しい indexPath を提供するときに起動する必要があります。
この indexPath を collectionView と組み合わせて使用してcellForItemAtIndexPath:
、特定のセルにアクセスします。
例:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[self manipulateCellAtIndexPath:indexPath];
}
-(void) manipulateCellAtIndexPath:(NSIndexPath*)indexPath {
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
// Now do what you want...
}
そして、私がここにいる限り。Swift バージョン:
override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
manipulateCellAtIndexPath(indexPath)
}
func manipulateCellAtIndexPath(indexPath: NSIndexPath) {
if let cell = collectionView?.cellForItemAtIndexPath(indexPath) {
// manipulate cell
}
}