zoukankan      html  css  js  c++  java
  • UICollectionView + AFNetWorking 异步加载,局部刷新.

    例子:https://github.com/KayCm/CellUpdate 

    最近在做的项目需要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];
    
            }
    
        }
    
    
    }
    复制代码
  • 相关阅读:
    《Qt学习系列笔记》--章节索引
    Qt-绘制图表
    Qt-可视化数据库操作
    Qt-数据库操作SQLite
    古人说的最好,临渊羡鱼,不如退而结网, 这是个勇气问题.
    阿里云产品之数据中台架构
    使用HSDB查看类变量的内存布局(5)
    文件流
    类文件介绍
    类的连接之重写(1)
  • 原文地址:https://www.cnblogs.com/Mrliheng/p/5476587.html
Copyright © 2011-2022 走看看