UICollectionView

TableViewCell加UIcollectionView

2016-04-23  本文已影响597人  yeshenlong520

TableCell加UICollectionView

好了进入正题直接上关键代码

这是tableCell里面的代码

   - (void)setSelected:(BOOL)selected animated:      (BOOL)animated {
     [super setSelected:selected animated:animated];
     _myCollectionView.delegate =self;
    _myCollectionView.dataSource =self;
    _myCollectionView.backgroundColor =[UIColor clearColor];
    _withScroll =_myCollectionView.contentSize.width;
   _collectionWith= _myCollectionView.frame.size.width;
    //这里是实现一个效果当他滑动范围超出UIcollectionView让他可以用户交互,
   反之不能交互,这样可以实现一个点击效果!集合视图能滑动让他滑动,
   不能滑动可以失去交互后点击可以实现tableCell点击事件
    if (_withScroll>_collectionWith) {
      _myCollectionView.userInteractionEnabled =YES;
    NSLog(@"yes");
    }else{
    _myCollectionView.userInteractionEnabled=NO;
     }
     NSLog(@"size=%f",_withScroll);
    UICollectionViewFlowLayout *layout =(UICollectionViewFlowLayout *)_myCollectionView.collectionViewLayout;
       layout.scrollDirection     =UICollectionViewScrollDirectionHorizontal;
     layout.itemSize =CGSizeMake(WIDTH/4, 100);
     [_myCollectionView setCollectionViewLayout:layout];
     [_myCollectionView registerNib:[UINib nibWithNibName:@"MyCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"MyCollectionCell"];
     // Configure the view for the selected state
    }
   -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
   {
    return _dataArr.count;
  }  
   -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MyCollectionCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"MyCollectionCell" forIndexPath:indexPath];
       cell.PhotoView.image =[UIImage imageNamed:_dataArr[indexPath.row]];
     return cell;
     }
      -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

      }
    -(void)setDataArr:(NSMutableArray *)dataArr{
    _dataArr =dataArr;

又该说再见的时候了,闲来无事整理总结!如有不妥之处请致电QQ309685725!

上一篇 下一篇

猜你喜欢

热点阅读