を使用しUICollectionView
てメニューを表示していますが、項目が非常に奇妙な方法で選択されています。
それらを入力する私の静的データは次のとおりです。
self.menuItems = @[@{@"text" : @"First", @"image" : @"180-stickynote.png"},
@{@"text" : @"Second", @"image" : @"180-stickynote.png"},
@{@"text" : @"Third", @"image" : @"180-stickynote.png"},
@{@"text" : @"Fourth", @"image" : @"180-stickynote.png"},
@{@"text" : @"Fifth", @"image" : @"180-stickynote.png"},
@{@"text" : @"Sixth", @"image" : @"180-stickynote.png"}];
カスタム サブクラスがプロトタイプ セルにアタッチされており、 と がUILabel
ありUIImageView
ます。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CUMenuCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MenuCell" forIndexPath:indexPath];
NSDictionary *cellInfo = [self.menuItems objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[cellInfo valueForKey:@"image"]];
cell.label.text = [cellInfo valueForKey:@"text"];
return cell;
}
タイトルとアイテムの行をログに記録する、did select row メソッドを次に示します (これらはすべてセクション 0 にあります)。
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@: %d", [[self.menuItems objectAtIndex:indexPath.row] valueForKey:@"text"], indexPath.row);
}
最後に、私のメニューのスクリーンショット:
これは、1 番目から 6 番目までの項目を選択し、6 番目から 1 番目 (1 番目、2 番目、3 番目、4 番目、5 番目、6 番目、6 番目、5 番目、4 番目、3 番目、2 番目、1 番目) に戻ったときのログです (合計 12 タップ、最初のタップは登録されず、2 回目の 6 番目のタップも登録されないことに注意してください):
------------------------------------- FIRST TAP ON FIRST HERE
2013-02-13 19:38:37.343 App[1383:c07] First: 0 // second tap, on Second
2013-02-13 19:38:38.095 App[1383:c07] Second: 1 // third tap, on Third
2013-02-13 19:38:38.678 App[1383:c07] Third: 2 // fourth tap, on Fourth
2013-02-13 19:38:39.375 App[1383:c07] Fourth: 3 // fifth tap, on Fifth
2013-02-13 19:38:40.167 App[1383:c07] Fifth: 4 // so on
2013-02-13 19:38:41.751 App[1383:c07] Sixth: 5
------------------------------------- SECOND TAP ON SIXTH HERE
2013-02-13 19:38:42.654 App[1383:c07] Fifth: 4
2013-02-13 19:38:43.318 App[1383:c07] Fourth: 3
2013-02-13 19:38:44.495 App[1383:c07] Third: 2
2013-02-13 19:38:45.071 App[1383:c07] Second: 1