码迷,mamicode.com
首页 > 其他好文 > 详细

CollectionView 下拉刷新 (第三方)

时间:2014-09-25 12:34:19      阅读:480      评论:0      收藏:0      [点我收藏+]

标签:collectionview 下拉刷新 (第三方)

使用第三方 :MJRefresh

NSString *const MJCollectionViewCellIdentifier = @"Cell";


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];



创建collectionView
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(80, 80);
    layout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
    layout.minimumInteritemSpacing = 20;
    layout.minimumLineSpacing = 20;
    
    self.Colletion = [[ColletionView alloc]initWithFrame:[[UIScreen mainScreen] bounds] collectionViewLayout:layout];
     self.Colletion.alwaysBounceVertical = YES;
    self.Colletion.backgroundColor = [UIColor purpleColor];
    self.Colletion.dataSource = self;
    [self.Colletion registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:MJCollectionViewCellIdentifier];
    [self addHeader];
    [self.window addSubview:self.Colletion];
    [self.Colletion release];





    [self.window makeKeyAndVisible];
    return YES;
}


- (void)addHeader
{
    __unsafe_unretained typeof(self) vc = self;
    // 添加下拉刷新头部控件
    [self.Colletion addHeaderWithCallback:^{
        // 进入刷新状态就会回调这个Block
        
        // 增加5条假数据
        //        for (int i = 0; i<5; i++) {
        //            [vc.fakeColors insertObject:MJRandomColor atIndex:0];
        //        }
        
        // 模拟延迟加载数据,因此2秒后才调用)
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [vc.Colletion reloadData];
            // 结束刷新
            [vc.Colletion headerEndRefreshing];
        });
    }];
    
}

#pragma mark - collection数据源代理
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 5;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   
 UICollectionViewCell *cell = [collectionView 
dequeueReusableCellWithReuseIdentifier:MJCollectionViewCellIdentifier 
forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    
    return cell;
}

CollectionView 下拉刷新 (第三方)

标签:collectionview 下拉刷新 (第三方)

原文地址:http://qccccc.blog.51cto.com/6004423/1557944

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