您好,登錄后才能下訂單哦!
使用第三方 :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; }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。