を に追加しようとしてUIRefreshControl
いUICollectionView
ますが、問題は、コレクション ビューが親コンテナーの高さを埋めない限り、更新コントロールが表示されないことです。つまり、コレクション ビューがスクロールを必要とするほど長くない限り、プルダウンして更新コントロール ビューを表示することはできません。コレクションがその親コンテナーの高さを超えるとすぐに、コレクションが引き下げられ、更新ビューが表示されます。
メインビューの内側だけで簡単なiOSプロジェクトをセットアップしUICollectionView
、コレクションビューへのアウトレットを使用して、に追加できるようにUIRefreshControl
しましたviewDidLoad
。再利用識別子を持つプロトタイプセルもありますcCell
これはコントローラー内のすべてのコードであり、問題をよく示しています。このコードでは、セルの高さを 100 に設定していますが、これはディスプレイを埋めるのに十分ではないため、ビューを取得できず、更新コントロールが表示されません。より高い値に設定してディスプレイをいっぱいにすると、機能します。何か案は?
@interface ViewController () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[self.collectionView addSubview:refreshControl];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
return [collectionView dequeueReusableCellWithReuseIdentifier:@"cCell" forIndexPath:indexPath];
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(self.view.frame.size.width, 100);
}