2

ページング UICollectionView を使用しようとしており、現在のページをプログラムで設定しようとしていますが、何もしません。常に0ページから始まります。

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flowLayout.minimumLineSpacing = 0;
flowLayout.minimumInteritemSpacing = 0;


// Set up the collection view with no scrollbars, paging enabled
// and the delegate and data source set to this view controller
self.collectionView = [[UICollectionView alloc]
                       initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)
                       collectionViewLayout:flowLayout];

self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.pagingEnabled = YES;
self.collectionView.delegate = self;
self.collectionView.dataSource = self;

[self.view addSubview:self.collectionView];


CGFloat w = self.view.frame.size.width;
CGFloat h = self.view.frame.size.height;

// Set up the page control
CGRect frame = CGRectMake(0, h - 60, w, 60);
self.pageControl = [[UIPageControl alloc]
                    initWithFrame:frame];

// Add a target that will be invoked when the page control is
// changed by tapping on it
[self.pageControl addTarget:self action:@selector(pageControlChanged:)
           forControlEvents:UIControlEventValueChanged];

// Set the number of pages to the number of pages in the paged interface
// and let the height flex so that it sits nicely in its frame
self.pageControl.numberOfPages = self.products.count;
self.pageControl.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.pageControl.currentPage=self.index;
[self.view addSubview:self.pageControl];
[self.collectionView registerClass:[DetailCustomCell class]
        forCellWithReuseIdentifier:@"CELL_ID"];
4

1 に答える 1