上出於某種原因,當我UICollectionView的第一頁上UICollectionView第二頁內容, 它顯示從第二頁的圖像。
而且我還注意到,該網頁不居中....
我手動設置
pageControl.numberOfPages = 3
所以,我有三個頁面圖像。 每個頁面顯示8項(理想情況下......)。
這是在viewDidLoad中:
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
[layout setSectionInset:UIEdgeInsetsMake(10, 10, 15, 10)];
[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[self.collectionView setCollectionViewLayout:layout];
self.collectionView = [[UICollectionView alloc] initWithFrame:keyboardRect collectionViewLayout:layout];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
self.collectionView.pagingEnabled = true;
self.collectionView.alwaysBounceHorizontal = true;
self.collectionView.contentSize = CGSizeMake(keyboardRect.size.width , keyboardRect.size.height);
self.collectionView.showsHorizontalScrollIndicator = false;
UINib *cellNib = [UINib nibWithNibName:@"TopCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cellIdentifier"];
[self.collectionView registerClass:[TopCollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
[self.collectionView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:self.collectionView];
當我試圖從
[layout setSectionInset:UIEdgeInsetsMake(10, 10, 15, 10)];
它只是使事情更糟提高左,右插圖。它只會在第一頁上看起來很好, 但是第二頁和第三頁將會關閉。
這裏是我的一些代碼:
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.Images count];
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(70, 70);
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView*)collectionView {
return 3;
}
預先感謝您!
爲collectionview和check設置pagingEnabled = TRUE。 – iOSEnthusiatic
它設置爲true。 (上面的代碼) –