小编现在才明白 其实uicollectionview与u i tableview 一样用
如果你用的是storyboard
在制作过程中,一定要注意好,datasource dalegate 的连接,还有一些自定义的东东与storyboard里面的连接
拖拽一个collectionview到当前的viewcontroller里面,勾掉use autolayout,collectionview里面自带了一个cell,下面就是自定义cell的代码,有两种方法,第一种
不用建立cell类 ,但是你必须标记好你cell里面的每个控件的tag值
如下:
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
return 6; //返回32张图片
}
//这个函数很关键,不懂怎么用可查查资料!
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"imgCell" forIndexPath:indexPath];
UILabel *titleLabel = (UILabel *)[cell viewWithTag:11];
NSString *sttr = [[NSString alloc] initWithFormat:@"Hello~%d",indexPath.row];
[titleLabel setText:sttr];
return cell;
}
// 向下一个视图传值
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"])
{
}
}