码迷,mamicode.com
首页 > Web开发 > 详细

UICollectionView + AFNetWorking 异步加载,局部刷新.

时间:2015-04-02 06:37:14      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:

最近在做的项目需要cell里面的数据需要和后台实时交互。而collectionview reload会整体刷新。

技术分享

 

 

//m层 发送通知
[[NSNotificationCenter defaultCenter]postNotificationName:@"CartProUpdate" object:self userInfo:par];

 
//c层 

//注册通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(UpdateForCells:) name:@"CartProUpdate" object:nil];

//收到通知后,更新cell
-(void)UpdateForCells:(NSNotification*)Notification

{

    NSLog(@"updateCell:%@",Notification.userInfo);
    //对比需要更新的cell,并更新CartInfo里的数据
    for (int i = 0; i< [CartInfo count]; i++) {

        if ([[CartInfo objectAtIndex:i][@"sysnumber"] isEqualToString:Notification.userInfo[@"sysnumber"]]) {

            if (Notification.userInfo[@"ifbuy"] == nil) {

                [[CartInfo objectAtIndex:i] setValue:[NSString stringWithFormat:@"%@",Notification.userInfo[@"num"]] forKey:@"quantity"];

            }else{

                [[CartInfo objectAtIndex:i] setValue:[NSString stringWithFormat:@"%@",Notification.userInfo[@"ifbuy"]] forKey:@"ifBuy"];

            }

            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];

           NSMutableArray *indexPaths = [[NSMutableArray alloc] init];

            [indexPaths addObject:indexPath];


            //更新cell
            [CartCollectionView reloadItemsAtIndexPaths:indexPaths];

        }

    }


}

 

UICollectionView + AFNetWorking 异步加载,局部刷新.

标签:

原文地址:http://www.cnblogs.com/ngi8/p/4384582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!