美文网首页
CollectionView最后一个item为添加按钮

CollectionView最后一个item为添加按钮

作者: CTBOY | 来源:发表于2016-07-12 10:50 被阅读0次
    #pragma mark - UICollectionViewDelegate
    //添加按钮之前返回的是数据源的count
    -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
    {
        NSInteger count = self.mDataArray.count + 1;
        return count;
    }
    
    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
    {
        
        if (indexPath.row == self.mDataArray.count)
        {
            //添加按钮对应的事件
                  ...
        }else{
            //添加按钮之前对应的点击事件
                  ...
        }
    }
    
    #pragma mark - UICollectionViewDataSource
    
    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        //自定义的addCell
        if (indexPath.row == self.mDataArray.count)
        {
            AddCollectionViewCell *addCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"addCell" forIndexPath:indexPath];
            [addCell cellForRowAtIndexPath:indexPath];
            return addCell;
        }
    
        MSFriendCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MSFriendCollectionCell" forIndexPath:indexPath];
        
        MSFriendData *friendData = self.mDataArray[indexPath.row];
        
        [cell setCellData:friendData isShowNick:isShowNick indexPath:indexPath];
        
        return cell;
        
    }
    
    

    相关文章

      网友评论

          本文标题:CollectionView最后一个item为添加按钮

          本文链接:https://www.haomeiwen.com/subject/zenjjttx.html