2016-10-27 26 views
1

我正在尋找一個水平滾動收藏視圖裏面的表視圖。這個水平集合視圖將是表視圖中許多行中的一個。這裏是我的原型單元格的圖片。Swift Collection視圖與表視圖

enter image description here

這裏是什麼,當我在模擬器中運行它,它產生的(只是顯示錶視圖):

enter image description here

這是我想讓它顯示什麼:

enter image description here

我不確定這是否是我的代碼中的問題,或者是否它可以在故事板中修復。

回答

0

在故事板中創建一個包含UICollectionView(您已完成)的原型單元格。將UIViewController設置爲UICollectionViewdataSource,然後爲UICollectionView添加所需的方法。

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ 
    //return the array showing number of collectionViewCells in tableViewCell. Of course you will have to handle the data showed in each tableView cell, (maybe using collectionView tags or some other logic) 
} 

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

} 
0

您只需要使用帶有customcell的UICollectionView而不是UITableView。例如,使用以下步驟輸出。

1。爲collectionView定義datasourece方法。

2。根據您的要求在collectionView的佈局代理方法下放置並自定義

-(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([UIScreen mainScreen].bounds.size.width/4 - 30, 150);//you need to resize height and width as per your requirement. 
} 

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