CollectionView最后一个item为添加按钮

2016-07-12  本文已影响0人  CTBOY
#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;
    
}

上一篇 下一篇

猜你喜欢

热点阅读