如何在sortedArrayUsingDescriptors数组之后重新加载collectionview

时间:2018-03-28 09:13:35

标签: objective-c iphone sorting collectionview

我尝试按如下方式对数组进行排序,发现NSLog结果将正确显示cell.productImage,cell.productName和cell.productPrice。但是,collectionview在执行后不会相应地重新加载。任何的想法?请帮忙。谢谢。

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {

    UICollectionReusableView *reusableview = nil;
    if (kind == UICollectionElementKindSectionHeader){

        DCCustionHeadView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:DCCustionHeadViewID forIndexPath:indexPath];
        WEAKSELF

        headerView.priceClickBlock = ^{//Click on price header

            cell = nil;
            cell = (_isSwitchGrid) ? [collectionView dequeueReusableCellWithReuseIdentifier:DCListGridCellID forIndexPath:indexPath] : [collectionView dequeueReusableCellWithReuseIdentifier:DCSwitchGridCellID forIndexPath:indexPath];


                if(_setItem.count >0){

                    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
                    NSArray *sortedArray = [_setItem sortedArrayUsingDescriptors:@[sortDescriptor]];

                    for (NSUInteger i=0; i<sortedArray.count; i++)
                    {
                        cell.productImage = [[sortedArray objectAtIndex:i] valueForKey:@"image"];
                        cell.productName = [[sortedArray objectAtIndex:i] valueForKey:@"name"];
                        cell.productPrice =  [[sortedArray objectAtIndex:i] valueForKey:@"price"];
                    }
                    [self.collectionView performBatchUpdates:^{
                        [collectionView reloadData];
                    } completion:nil];
                }

            }

        };

        reusableview = headerView;
    }  
}

0 个答案:

没有答案