2016-06-16 10 views
-2

UICollectionViewは複数のセルで実装されていますか?*非常に単純* "=="への呼び出し結果は未使用

セルをクリックすると、selectedArrayの値をtrueに変更します。すべてのセルが、私は何かが正しくリンクされていない知っているが、私はそれを見ていないので、クリックのため

var selectedArray = [Bool](count:201, repeatedValue:false) 

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { 
    let cell = collectionView.cellForItemAtIndexPath(indexPath) 
    if cell?.selected == true { 
     selectedArray[indexPath.row] == true 
     print("\(selectedArray[indexPath.row])") 
    } 
} 

出力が偽である:

は、ここに私のコードです。

+0

NSMutableIndexSetは、選択を追跡するためにより適切なデータ構造です。 – Paulw11

答えて

0

selectedArray[indexPath.row] == trueは - あなたは、セルが選択されているかどうかを確認する必要はありません

+0

hhmm私はifセルを選択しました。選択された行と私はまだ同じ結果を取得しています@Savchenko – Cameron

+0

@Cameron、strange .. what selected elerayでも何をしていますか? –

+0

まだ、私はfuncの2つの行を持っています:selectedArray [indexPath.row] == trueおよび print( "\(selectedArray [indexPath.row])") – Cameron

2

「=」から「==」置き換える必要があります。 didSelectItemAtIndexPathに電話しているため、これを確認する必要はありません。単にこれを実行してください:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { 
    selectedArray[indexPath.row] = true 
} 
関連する問題