ios uicollectionview 初使用 (一)

小编现在才明白  其实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"])
    {
     
     
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值