首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >仅当集合填满容器的高度时,UICollectionView上的UIRefreshControl才有效

仅当集合填满容器的高度时,UICollectionView上的UIRefreshControl才有效
EN

Stack Overflow用户
提问于 2013-02-04 07:48:15
回答 7查看 65.4K关注 0票数 147

我正在尝试向UICollectionView添加一个UIRefreshControl,但问题是,除非集合视图填满其父容器的高度,否则刷新控件不会出现。换句话说,除非集合视图足够长而需要滚动,否则无法向下拖动以显示刷新控件视图。一旦集合超过其父容器的高度,它就会被拉下并显示刷新视图。

我已经设置了一个快速的iOS项目,在主视图中只有一个UICollectionView,还有一个指向集合视图的出口,这样我就可以在viewDidLoad中向其中添加UIRefreshControl。还有一个具有重用标识符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);
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14678727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档