我需要將UICollectionView
添加到UICollectionViewCell
。這似乎很容易,但我不明白。UICollectionView到UICollectionViewCell
我也不瞭解,我必須初始化UICollectionView
每個UICollectionViewCell
並在編程UICollectionViewDataSource
每個UICollectionView
的UICollectionViewDelegate
。
結果將是產品的集合(第一個collectionview
,其中每個單元格都是產品)以及每個產品(如圖像庫(第二個集合視圖,其中每個單元格都是圖像))的圖像集合。這與Zara app相同。
第一個集合視圖看起來像這樣,只有垂直滾動。
當你選擇一個產品,細胞改變它們的大小,以全屏幕大小和集合視圖改變垂直滾動水平滾動。現在垂直滾動用於第二個集合視圖,即圖像庫。
二集視圖看起來像這樣
在故事板我UICollectionViewController
與UICollectionViewDataSource
,UICollectionViewDelegate
和UICollectionViewDelegateFlowLayout
實現。
ProductsCollectionViewController.h
@interface ProductsCollectionViewController : UICollectionViewController <UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout> {
NSMutableArray *products;
}
ProductsCollectionViewController.m
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return products.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"ProductCell";
ProductCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
Product *product = [products objectAtIndex:indexPath.row];
[cell setProduct:product];
return cell;
}
產品是有一些信息,也圖像的array
主要NSObject
。
Product.h
@interface Product : NSObject
@property NSInteger categoryID;
@property NSInteger productID;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *description;
@property (nonatomic, strong) NSArray *images;
我認爲我必須做的是創造新的UICollectionView
編程每個ProductCollectionViewCell
與產品的圖像array
但ProductCollectionViewCell
不承認UICollectionViewDataSource
和UICollectionViewDelegate
及其實施。
嗯...好像你讓過於複雜。你試圖達到什麼目標? – Fogmeister
你能澄清你想達到什麼嗎?你也使用故事板或以編程方式設置一切嗎? – tanzolone
我需要做這樣的http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell,但與UICollectionViewController而不是UITableViewController。如果你需要我可以放一些代碼來澄清。 –