在viewcontroller中重新加载三个collectionview很慢

时间:2015-10-15 12:48:33

标签: ios uicollectionview

在我的应用程序中,viewcontroller中有三个collectionview。 Collectionview在重新加载collectionview数据时很慢。

事件我已经在主队列中重新加载了集合。有人可以帮忙吗?

      dispatch_async(dispatch_get_main_queue(), ^{

                    [topProductCollectionView reloadData];
                    [recentProductCollectionView reloadData];
                    [specialOfferCollectionView reloadData];
                });

    Below code for collectionview cell:

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

            switch (collectionView.tag)
            {
                case 1:
                {
                    static NSString *cellIdentifier = @"TopProductCell";
                    TopProductCell *topCell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

   // Loading image in background Queue
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
                        NSString *imageurl = [[topProducts valueForKey:@"image"]objectAtIndex:indexPath.item];
                         NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageurl]];

                        dispatch_sync(dispatch_get_main_queue(), ^{
                           topCell.topProductImg.image = [UIImage imageWithData:imageData];
                        });
                    });


                    topCell.topProductName.text = [[topProducts valueForKey:@"product_name"]objectAtIndex:indexPath.item];

                    topCell.topProductPrice.text = [[topProducts valueForKey:@"product_finalprice"]objectAtIndex:indexPath.item];

                    return topCell;
                }
                    break;
        }

0 个答案:

没有答案