

collectionView的模拟创建.zip
#import "FindProductNew.h"
#import "SHStoreCollectionCell.h"
#import "HeaderSectionView.h"
@interface FindProductNew ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *rightCollection;
@end
@implementation FindProductNew
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor];
#pragma 配置文件
self.rightCollection.delegate = self;
self.rightCollection.dataSource = self;
#warning 在storyboard中,不能使用下面的代码,否则cell中的内容都不显示
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
HeaderSectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"HeaderSectionView" forIndexPath:indexPath];
return headerView;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 10;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
#pragma mark 在storyboard中重用identifier与这个要一致
static NSString * identifierCell = @"SHStoreCollectionCell";
SHStoreCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifierCell forIndexPath:indexPath];
cell.placeLabel.text = @"张家界";
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end