Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UICollectionView中添加更多称重传感器?_Ios_Objective C_Uicollectionview_Uicollectionviewlayout - Fatal编程技术网

Ios 如何在UICollectionView中添加更多称重传感器?

Ios 如何在UICollectionView中添加更多称重传感器?,ios,objective-c,uicollectionview,uicollectionviewlayout,Ios,Objective C,Uicollectionview,Uicollectionviewlayout,我想在UICollectionview中添加更多称重传感器?谁能告诉我如何添加加载按钮?我已经创建了collectionview,可以正常工作,但我想在collection view单元格的底部添加Load more按钮,如 这是我的收藏视图 #pragma mark <UICollectionViewDataSource> - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionVie

我想在UICollectionview中添加更多称重传感器?谁能告诉我如何添加加载按钮?我已经创建了collectionview,可以正常工作,但我想在collection view单元格的底部添加Load more按钮,如

这是我的收藏视图

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
      return 3;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
     switch (section) {
            case 0: return 66;
            case 1: return 123;
     }
     return 31;
 }

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

   NSUInteger row = [indexPath row];
   NSUInteger count = [self.stockImages count];

   if (row == count) {

        //Add load more cell
   }

  DemoCellView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[DemoCellView reuseIdentifier] forIndexPath:indexPath];

  // Configure the cell
  cell.titleLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.item + 1];
  NSLog(@"%@", self.stockImages[indexPath.item % self.stockImages.count]);
  cell.imageView.image = self.stockImages[indexPath.item % self.stockImages.count];

  return cell;
}


#pragma mark <DemoLayoutDelegate>

- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

     // Do something 
     // Insert new cell after clicking load more data 

}

 - (CGFloat)collectionView:(UICollectionView *)collectionView layout: (UICollectionViewLayout *)collectionViewLayout heightForHeaderInSection:(NSInteger)section {
     return kFMHeaderFooterHeight;
}

  - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout heightForFooterInSection:(NSInteger)section {
    return kFMHeaderFooterHeight;
 }
#pragma标记
-(NSInteger)collectionView中的节数:(UICollectionView*)collectionView{
返回3;
}
-(NSInteger)collectionView:(UICollectionView*)collectionView项目编号截面:(NSInteger)截面{
道岔(区段){
案例0:返回66;
案例1:返回123;
}
返回31;
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{
NSUTEGER行=[indexPath行];
NSU整数计数=[self.stockImages计数];
如果(行==计数){
//添加更多称重传感器
}
DemoCellView*cell=[collectionView dequeueReusableCellWithReuseIdentifier:[DemoCellView reuseIdentifier]forIndexPath:indexPath];
//配置单元格
cell.titleLabel.text=[NSString stringWithFormat:@“%ld”,长)indexPath.item+1];
NSLog(@“%@”,self.stockImages[indexath.item%self.stockImages.count]);
cell.imageView.image=self.stockImages[indexath.item%self.stockImages.count];
返回单元;
}
#布拉格标记
-(void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{
//做点什么
//单击“加载更多数据”后插入新单元格
}
-(CGFloat)集合视图:(UICollectionView*)集合视图布局:(UICollectionViewLayout*)集合视图头部布局高度截面:(NSInteger)截面{
返回kfmheaderfooteheight;
}
-(CGFloat)collectionView:(UICollectionView*)collectionView布局:(UICollectionViewLayout*)collectionViewLayout页脚高度:(NSInteger)部分{
返回kfmheaderfooteheight;
}

您可以添加页脚

- (UICollectionReusableView *)collectionView:(JSQMessagesCollectionView *)collectionView
           viewForSupplementaryElementOfKind:(NSString *)kind
                                 atIndexPath:(NSIndexPath *)indexPath
{
    if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {

        //load your footer you have registered earlier for load more 
        [super dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter
                                                                             withReuseIdentifier:@“load more footer”
                                                                                    forIndexPath:indexPath];
    }

    return nil;
}

cellForItemAtIndexPath
方法中,您可以检查以下内容:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ImageCollectionViewCell *cellImage;
    AddMoreCollectionViewCell *addMoreCell;
    if(indexPath.row < [_dataSource numberOfItems]){
        cellImage = [collectionView dequeueReusableCellWithReuseIdentifier:ImageCollectionCellIdentifier
                                                              forIndexPath:indexPath];
        [cellImage configureForMediaViewModel:[_dataSource mediaViewModelForItemIndex:indexPath.row] delegate:self];
        return cellImage;
    }else{
        addMoreCell = [collectionView dequeueReusableCellWithReuseIdentifier:AddMoreCollectionCellIdentifier
                                                                forIndexPath:indexPath];
        addMoreCell.delegate = self;
        return addMoreCell;

    }
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{
ImageCollectionViewCell*cellImage;
AddMoreCollectionViewCell*addMoreCell;
if(indexath.row<[\u数据源numberOfItems]){
cellImage=[collectionView dequeueReusableCellWithReuseIdentifier:ImageCollectionCellIdentifier
forIndexPath:indexPath];
[cellImage configureForMediaViewModel:[\u数据源mediaViewModelForItemIndex:indexPath.row]委托:self];
返回图像;
}否则{
addMoreCell=[collectionView dequeueReusableCellWithReuseIdentifier:AddMoreCollectionCellIdentifier
forIndexPath:indexPath];
addMoreCell.delegate=self;
返回addMoreCell;
}
}
其中,
ImageCollectionViewCell
是主要的单元格类型,
AddMoreCollectionViewCell
是带有加号(“+”)符号和其他内容的单元格

使用此方法,
AddMoreCollectionViewCell
始终在集合视图的末尾添加

希望有帮助