CollectionView 下拉刷新 (第三方)
使用第三方 :MJRefresh
NSString*constMJCollectionViewCellIdentifier=@"Cell";-(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{self.window=[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];//Overridepointforcustomizationafterapplicationlaunch.self.window.backgroundColor=[UIColorwhiteColor];创建collectionViewUICollectionViewFlowLayout*layout=[[UICollectionViewFlowLayoutalloc]init];layout.itemSize=CGSizeMake(80,80);layout.sectionInset=UIEdgeInsetsMake(20,20,20,20);layout.minimumInteritemSpacing=20;layout.minimumLineSpacing=20;self.Colletion=[[ColletionViewalloc]initWithFrame:[[UIScreenmainScreen]bounds]collectionViewLayout:layout];self.Colletion.alwaysBounceVertical=YES;self.Colletion.backgroundColor=[UIColorpurpleColor];self.Colletion.dataSource=self;[self.ColletionregisterClass:[UICollectionViewCellclass]forCellWithReuseIdentifier:MJCollectionViewCellIdentifier];[selfaddHeader];[self.windowaddSubview:self.Colletion];[self.Colletionrelease];[self.windowmakeKeyAndVisible];returnYES;}-(void)addHeader{__unsafe_unretainedtypeof(self)vc=self;//添加下拉刷新头部控件[self.ColletionaddHeaderWithCallback:^{//进入刷新状态就会回调这个Block//增加5条假数据//for(inti=0;i<5;i++){//[vc.fakeColorsinsertObject:MJRandomColoratIndex:0];//}//模拟延迟加载数据,因此2秒后才调用)dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(2.0*NSEC_PER_SEC)),dispatch_get_main_queue(),^{[vc.ColletionreloadData];//结束刷新[vc.ColletionheaderEndRefreshing];});}];}#pragmamark-collection数据源代理-(NSInteger)collectionView:(UICollectionView*)collectionViewnumberOfItemsInSection:(NSInteger)section{return5;}-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionViewcellForItemAtIndexPath:(NSIndexPath*)indexPath{UICollectionViewCell*cell=[collectionViewdequeueReusableCellWithReuseIdentifier:MJCollectionViewCellIdentifierforIndexPath:indexPath];cell.backgroundColor=[UIColorredColor];returncell;}附件:http://down.51cto.com/data/2364897
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。