2015-09-28 65 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中有单行 –