2015-09-28 64 views
1

我使用ScrollView。在我的滾動視圖中有集合視圖。我的收藏視圖最後3個元素隱藏在白色空間內。在滾動ScrollView他們不顯示。他們顯示在滾動CollectionView。我想在Scroll ScrollView中顯示所有收集單元格。不滾動CollectionView。我的收藏查看單元隱藏

-(NSInteger)numberOfSectionsInCollectionView: 
(UICollectionView *)collectionView { 

    return 1; // The number of sections we want 
} 
-(NSInteger)collectionView:(UICollectionView *)collectionView 
    numberOfItemsInSection:(NSInteger)section { 

    return 5; // the number of cells we want 
} 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionViewd 
        cellForItemAtIndexPath:(NSIndexPath *)indexPath { 

    CollectionCell* cell = 
    [collectionViewd dequeueReusableCellWithReuseIdentifier:@"collectionView2CellIdentifier" 
               forIndexPath:indexPath]; // Create the cell from the storyboard cell 

    cell.layer.cornerRadius = 4; 
    cell.layer.borderWidth = 1; 
    cell.layer.borderColor = [UIColor grayColor].CGColor; 

    cell.yellow.layer.cornerRadius=4; 
    cell.red.layer.cornerRadius=4; 


    cell.title.text =[titleArray objectAtIndex:indexPath.row]; 
    cell.date.text =[dateArray objectAtIndex:indexPath.row]; 
    cell.incomeText.text =[netIncomeArray objectAtIndex:indexPath.row]; 
    cell.expenseText.text =[netExpenseArray objectAtIndex:indexPath.row]; 
    cell.saving.text =[savingArray objectAtIndex:indexPath.row]; 
    cell.expensePecentageText.text =[expensePercentage objectAtIndex:indexPath.row]; 
    cell.savingPercentage.text =[netProfitPercentage objectAtIndex:indexPath.row]; 

    return cell; // Return the cell 
} 

- (CGFloat)collectionView:(UICollectionView *) collectionView 
        layout:(UICollectionViewLayout *) collectionViewLayout 
minimumInteritemSpacingForSectionAtIndex:(NSInteger) section { 
    return 2.0; 
} 


- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section 
{ 
    return UIEdgeInsetsMake(2, 2, 2, 2); 
} 
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 

    return CGSizeMake(155, 158); 

} 
    [scrollView setContentSize:CGSizeMake(0, expenseButton.frame.origin.y+expenseButton.frame.size.height+collection.frame.size.height+16)]; 
+0

嘗試將scrollview高度設置爲集合視圖高度。 – sohil

+0

@Sohil我在設置[scrollView setContentSize:CGSizeMake(0,expenseButton.frame.origin.y + expenseButton.frame.size.height + collection.frame.size.height + 16)]; –

+0

當你設置setContentSize?加載收藏之前或之前 – sohil

回答

1

首先計數的CollectionView的高度通過:

對於實施例

titleArray.count * 160(158px單元高度+ 2px的單元空間)

然後分配此高度collectionview框架

也將此分配給滾動視圖內容大小高度。

這一定會爲你做的伎倆。

+1

這將不會接受,因爲在Iphone 6中有一個行上有兩個單元格,在一個iPhone 5中有單行 –