集合视图仅在IOS中的页面加载时加载

时间:2014-06-12 10:35:52

标签: ios7 uicollectionview

我正在使用Collection View在用户选择的滑块中显示多个图像,但主要问题是集合视图仅在页面加载时加载。我的包含图像的数组是在页面加载后制作的。这就是为什么没有加载图像的原因,因为加载页面后没有加载集合视图。 我不太了解Collection View所以请引导我... 我的代码如下: -

- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
 {
   [self dismissViewControllerAnimated:YES completion:nil];

   _imageList= [NSMutableArray arrayWithCapacity:[info count]];

for (NSDictionary *dict in info)
{
   UIImage *image  = [dict objectForKey:UIImagePickerControllerOriginalImage];
    [_imageList addObject:image];

}

self.chosenImages = _imageList;

}

- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
{
 [self dismissViewControllerAnimated:YES completion:nil];
}


  -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

   return 1;
  }

 -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:  (NSInteger)section{

    int numberOfItem = 0;
     if (_imageList)
     {

       numberOfItem = _imageList.count;
      }
   return numberOfItem;
 }

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

  static NSString *cellIdentifier = @"ImageCell";
    [collectionView registerClass:[ImageCell class]   forCellWithReuseIdentifier:cellIdentifier];
    ImageCell *cell = (ImageCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier
                                                                           forIndexPath:indexPath];
    //    if(LOGS_ON) NSLog(@"cell = %@",cell);
      if (!cell) {

    //        if(LOGS_ON) NSLog(@"Creating cell");
    cell          = [[ImageCell alloc] initWithFrame:CGRectMake(0, 0, 85, 110)];
    cell.delegate = self;
   }
   cell.delegate  = self;
    cell.indexPath = indexPath;

  //    if(LOGS_ON) NSLog(@"image = %@", cell.imageView);

    cell.cellImage.image = [UIImage imageNamed:[_imageList objectAtIndex:indexPath.row]];
    return cell;
    }


   -(void) imageCell:(ImageCell *)imageCell buttonClickedAtIndexPath:(NSIndexPath *)indexPath{

    [_imageList removeObjectAtIndex:indexPath.row];
    [_imageGrid reloadData];
   }
集合视图中的

_imageList未加载项目

1 个答案:

答案 0 :(得分:0)

加载imageList后,重新加载集合视图

- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
 {
   [self dismissViewControllerAnimated:YES completion:nil];

   _imageList= [NSMutableArray arrayWithCapacity:[info count]];

for (NSDictionary *dict in info)
{
   UIImage *image  = [dict objectForKey:UIImagePickerControllerOriginalImage];
    [_imageList addObject:image];

}

self.chosenImages = _imageList;

//重新加载集合视图

[collectionview reloadData];

}