如何反转集合视图单元格

Satheeshkumar Naidu

我有一个包含15个元素的数组,我正在将它们添加到集合视图单元格中

_imagearray=[@[@"bootimages",@"fall-photography-in-hocking-hills", @"gift",@"hillimages",@"Mercedes-classe-S-W116_large_dettaglio_articolo",@"prinimages",@"resplendent",@"tnb4",@"Tomato-plant",@"Vole",@"waterimages",@"fall-photography-in-hocking-hills", @"gift",@"hillimages",@"Mercedes-classe-S-W116_large_dettaglio_articolo"]mutableCopy];

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

     //[self.collection reloadData];
    homeceeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

    UIImage *image;
    NSInteger row = [indexPath row];


    NSLog(@"indexpath = %ld", (long)row);

        image = [UIImage imageNamed:_imagearray[row]];

    cell.img.image = image;

    cell.text.text=[_tittlearray objectAtIndex:indexPath.row];

        return cell;
}

我在下一个视图控制器中,我使用相机拍摄图像并将其保存到阵列中,然后使用以下方法将阵列传递回第一个视图控制器中 NSNotificationCenter

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedArray:) name:@"ShareArray" object:nil];

-(void) receivedArray:(NSNotification*)notification
{

        NSMutableArray* userInfo = notification.object;
    UIImage *image = [userInfo firstObject];

        [_imagearray addObject:[userInfo firstObject]];

    NSLog(@"%@",_imagearray);
      [self.collection reloadData];
    _collection.delegate=self;
    _collection.dataSource=self;


    NSLog(@"%@",_imagearray);
}
I am Reloading the collection view cell and the new image doesn't have name  
if (indexPath.row == 15) {
       image= _imagearray[row];

                //[_imagearray insertObject:image atIndex:0];

    }else {
        image = [UIImage imageNamed:_imagearray[row]];


    }
    cell.img.image = image;

    cell.text.text=[_tittlearray objectAtIndex:indexPath.row];
}

我想在顶部添加新图像,但在底部

请帮助我,我对目标c还是陌生的

哈里·克里希南

检查我的答案@ sathees

imagearray=[@[@"bootimages",@"fall-photography-in-hocking-hills", @"gift",@"hillimages",@"Mercedes-classe-S-W116_large_dettaglio_articolo",@"prinimages",@"resplendent",@"tnb4",@"Tomato-plant",@"Vole",@"waterimages",@"fall-photography-in-hocking-hills", @"gift",@"hillimages",@"Mercedes-classe-S-W116_large_dettaglio_articolo"]mutableCopy];

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

     //[self.collection reloadData];
    homeceeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

    UIImage *image;
    NSInteger row = [indexPath row];


    NSLog(@"indexpath = %ld", (long)row);
   // here i have make the changes** 
    if( [_imagearray[row] isKindOfClass:[UIImage class]]){
       image = _imagearray[row]
    }
   else {
        image = [UIImage imageNamed:_imagearray[row]];
    }

    cell.img.image = image;

    cell.text.text=[_tittlearray objectAtIndex:indexPath.row];

        return cell;
}


 -(void) receivedArray:(NSNotification*)notification {

    NSMutableArray* userInfo = notification.object;
   if([userInfo count]>0) {
    UIImage *image = [userInfo firstObject];
    ///[_imagearray addObject:[userInfo firstObject]];  use this it will diretly add to end of the last index
    [_imagearray insertObject:[userInfo firstObject] atIndex:0];  // it will add to firstindex of the array value
    NSLog(@"%@",_imagearray);
    [self.collection reloadData];
     // here do not want add the delegate itself.
    NSLog(@"%@",_imagearray);
    }  // it will check the nil object and to prevent the crash
 }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何找出在集合视图单元格内点击了哪个集合视图单元格

来自分类Dev

如何仅使用静态单元格创建集合视图?

来自分类Dev

如何在集合视图单元格中插入图像

来自分类Dev

如何在集合视图中单选单元格?

来自分类Dev

如何快速设置集合视图单元格的动态高度?

来自分类Dev

如何仅使用静态单元格创建集合视图?

来自分类Dev

如何通过Segue发送集合视图单元格文本

来自分类Dev

如何选择何时返回集合视图单元格

来自分类Dev

集合视图内的两个定向单元格,如何获取单元格标题?

来自分类Dev

集合视图更改单元格大小

来自分类Dev

集合视图单元格内容分层

来自分类Dev

集合视图更改单元格大小

来自分类Dev

确定集合视图单元格的大小

来自分类Dev

如何将集合视图单元格设置为所有屏幕的相等行单元格

来自分类Dev

如何设置集合视图的动态高度,而不是“视图”的“单元格”?

来自分类Dev

呈现弹出视图时,如何让用户在父集合视图中选择单元格?

来自分类Dev

如何从不同的集合视图单元格选择到不同的视图控制器

来自分类Dev

RxSwift:如何使用ViewModel在表格视图内的集合视图单元格中填充数据?

来自分类Dev

如何使集合视图中的不同单元格进入Swift中的不同视图控制器

来自分类Dev

如何在集合视图单元格中更改图像视图

来自分类Dev

如何通过快速点击集合视图的单元格在表视图中重新加载数据

来自分类Dev

来自笔尖的表格视图单元格中的集合视图

来自分类Dev

在特定的集合视图单元格上显示视图?

来自分类Dev

如何通过单击更改集合视图单元格中的标签颜色

来自分类Dev

如何修复表格视图中各节中的单元格分离集合?

来自分类Dev

使用两种不同类型的单元格时如何确定集合视图的大小

来自分类Dev

如何在行集合视图中制作2个单元格

来自分类Dev

如何在集合视图单元格中更改图像

来自分类Dev

选中后如何更改集合视图单元格的背景颜色?

Related 相关文章

  1. 1

    如何找出在集合视图单元格内点击了哪个集合视图单元格

  2. 2

    如何仅使用静态单元格创建集合视图?

  3. 3

    如何在集合视图单元格中插入图像

  4. 4

    如何在集合视图中单选单元格?

  5. 5

    如何快速设置集合视图单元格的动态高度?

  6. 6

    如何仅使用静态单元格创建集合视图?

  7. 7

    如何通过Segue发送集合视图单元格文本

  8. 8

    如何选择何时返回集合视图单元格

  9. 9

    集合视图内的两个定向单元格,如何获取单元格标题?

  10. 10

    集合视图更改单元格大小

  11. 11

    集合视图单元格内容分层

  12. 12

    集合视图更改单元格大小

  13. 13

    确定集合视图单元格的大小

  14. 14

    如何将集合视图单元格设置为所有屏幕的相等行单元格

  15. 15

    如何设置集合视图的动态高度,而不是“视图”的“单元格”?

  16. 16

    呈现弹出视图时,如何让用户在父集合视图中选择单元格?

  17. 17

    如何从不同的集合视图单元格选择到不同的视图控制器

  18. 18

    RxSwift:如何使用ViewModel在表格视图内的集合视图单元格中填充数据?

  19. 19

    如何使集合视图中的不同单元格进入Swift中的不同视图控制器

  20. 20

    如何在集合视图单元格中更改图像视图

  21. 21

    如何通过快速点击集合视图的单元格在表视图中重新加载数据

  22. 22

    来自笔尖的表格视图单元格中的集合视图

  23. 23

    在特定的集合视图单元格上显示视图?

  24. 24

    如何通过单击更改集合视图单元格中的标签颜色

  25. 25

    如何修复表格视图中各节中的单元格分离集合?

  26. 26

    使用两种不同类型的单元格时如何确定集合视图的大小

  27. 27

    如何在行集合视图中制作2个单元格

  28. 28

    如何在集合视图单元格中更改图像

  29. 29

    选中后如何更改集合视图单元格的背景颜色?

热门标签

归档