溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

CollectionView 下拉刷新 (第三方)

發(fā)布時(shí)間:2020-06-14 11:42:02 來(lái)源:網(wǎng)絡(luò) 閱讀:1671 作者:緣起愿落 欄目:開(kāi)發(fā)技術(shù)


使用第三方 :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];



創(chuàng)建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:^{
        // 進(jìn)入刷新?tīng)顟B(tài)就會(huì)回調(diào)這個(gè)Block
        
        // 增加5條假數(shù)據(jù)
        //        for (int i = 0; i<5; i++) {
        //            [vc.fakeColors insertObject:MJRandomColor atIndex:0];
        //        }
        
        // 模擬延遲加載數(shù)據(jù),因此2秒后才調(diào)用)
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [vc.Colletion reloadData];
            // 結(jié)束刷新
            [vc.Colletion headerEndRefreshing];
        });
    }];
    
}

#pragma mark - collection數(shù)據(jù)源代理
- (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;
}
附件:http://down.51cto.com/data/2364897
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI