UICollectionViewを使用しているとき、私はdidSelectItemAtIndexPath
メソッドのindexPath
の値を得ることに困惑しています。UICollectionViewのindexPathの値
IはdidSelectItemAtIndexPath
方法で次のコード行を使用している:
//FileList is an NSArray of files from the Documents Folder within my app.
//This line gets the indexPath of the selected item and finds the same index in the Array
NSString *selectedItem = [NSString stringWithFormat:@"%@",[FileList objectAtIndex:indexPath.item]];
//Now the selected file name is displayed using NSLog
NSLog(@"Selected File: %@", selectedItem);
問題はindexPathは常に0(コード下記参照)、その結果としてのみ最初の項目を返すことですFileList NSArrayが選択されます。
私はこれらのすべては、次のNSLog文で0の値を返すように
indexPath.row
indexPath.item
- と単なる
indexPath
など、さまざまなパラメータを試してみました:
NSLog(@"index path: %d", indexPath.item); //I also tried indexPath.row here
たぶん私はNSStringを不適切にフォーマットしているだけですが、警告がなく、別の場所で書式を設定しようとしたため、これは当てはまりません。
なぜindexPathは常に0を返しますか?
ご協力いただければ幸いです!ありがとう!
'NSLog'の文字列の書式を示してください。 – dasblinkenlight
' .item'はここでは適切なプロパティですが、機能的には '.row'と違いはありません。もっと見る必要があります - それがゼロであることをどのように知っていますか? FileListとは何ですか? – jrturton
私は質問を編集し、NSLogの文字列をどのように書式設定するかを含めました.FileListの内容を明確にしました(コメントコードをお読みください) –