UICollectionView + AFNetWorking 异步加载,局部刷新.
最近在做的项目需要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]; } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。