0

I have UICollectionView with 2 sections: first is the Upload Cells with its progress (and i need to remove it after uploading), second one has the all photos; When im adding photo, i use KVO method

NSDictionary *uploadInfo = @{@"progress": progress, @"image": image, @"task": uploadTask, @"params": params};
[[NSNotificationCenter defaultCenter] postNotificationName:@"APIClientDidUploadingPhotoNotification" object:uploadInfo];

notification method get it

- (void)photoUploadAdded:(NSNotification*)notofication
{
  NSDictionary *uploadInfo = [notofication object];
  NSLog(@"Added photo upload: %@", uploadInfo[@"progress"]);

  if (!self.photoUploadQueue) {
    self.photoUploadQueue = [NSMutableArray array];
  }
  [self.photoUploadQueue addObject:uploadInfo];

  dispatch_async(dispatch_get_main_queue(), ^
               {
                   [self.collectionView reloadData];
               });
}

in cellforItem i use

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

  if (indexPath.section == 0) {
    cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UploadCell" forIndexPath:indexPath];
    [((PhotoUploadCell*)cell) setDelegate:self];
    if ([self.photoUploadQueue count]>0)
        [((PhotoUploadCell*)cell) setUploadInfo:self.photoUploadQueue[indexPath.row]];
   ...
}

and when photo is loaded i remove it

- (void)uploadCompletedForCell:(id)cell
{
  NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
  [self.photoUploadQueue removeObjectAtIndex:indexPath.row];
//[self.collectionView reloadData];
}

it's not working as i expect,
This controller dealloceted sometime and notification don't work. i feel it is not the best solution. Maybe i should use ReactiveCocoa (but im not use it before) or some another solution

0 Answers0