2014-04-19 86 views
0

我为UICollectionView实施了UIRefreshControl,这样用户就可以拉动以刷新UICollectionView中的内容。我正在iPad模拟器上测试。UIRefreshControl加载图标仍在加载

第一次尝试时,我可以拉取和刷新内容。但是,我注意到加载图标仍在加载并且不停止。在我第二次尝试加载图标仍然显示时,我拉起来刷新,但它没有打电话给我的选择器(refreshCollectionAction)。

这里是我做过什么:

-(void)viewDidLoad 
{ 
    // Do any additional setup after loading the view. 
    [super viewDidLoad]; 

    // Register collectionView pull down to refresh 
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; 
    [refreshControl addTarget:self action:@selector(refreshCollectionAction) 
      forControlEvents:UIControlEventValueChanged]; 
    [self.collectionView addSubview:refreshControl]; 
    self.collectionView.alwaysBounceVertical = YES; 
..... 
} 

-(void)refreshCollectionAction 
{ 
    NSLog(@"refresh collection action"); 

    // Empty product Items Array 
    [[ProductStore getInstance] emptyProductInStore]; 

    NSInteger numOfProductInStore = [[[ProductStore getInstance] allProductItems] count]; 
    if (numOfProductInStore <= 0) { 
     // Fetch data from webservice and reload collectionView 
     [self fetchFeed:@""]; 
    } 
} 

我错过了一些配置? fetchFeed将向Web服务请求数据。我已经证实,web服务仍然有效。

回答

3
[self.refreshControl endRefreshing]; 

调用此方法可在任何刷新操作结束(它是否被编程或由用户发起)返回刷新控制到其默认状态。如果刷新控件至少部分可见,则调用此方法也会隐藏它。如果还启用了动画,则该控件将使用动画隐藏。 UIRefreshControl Class Reference

+0

Добрыйдень。来自新加坡。非常感谢你。它现在正在工作。我会在一段时间后发布我的解决方案。 – nuttynibbles

+0

:)如果它解决了您的问题,然后将其标记为答案。 –

1
@interface ProductSearchViewController() 

@property(nonatomic)UIRefreshControl *refreshControl; 

@end 

- (void)viewDidLoad 
{ 
    // Do any additional setup after loading the view. 
    [super viewDidLoad]; 

    // Register collectionView pull down to refresh 
    self.refreshControl = [[UIRefreshControl alloc] init]; 
    [self.refreshControl addTarget:self action:@selector(refreshCollectionAction) 
      forControlEvents:UIControlEventValueChanged]; 
    [self.collectionView addSubview:self.refreshControl]; 
    self.collectionView.alwaysBounceVertical = YES; 

... 
} 

-(void)refreshCollectionAction 
{ 
    NSLog(@"refresh collection action"); 

    // Empty product Items Array 
    [[posProductStore getInstance] emptyProductInStore]; 

    NSInteger numOfProductInStore = [[[posProductStore getInstance] allProductItems] count]; 
    if (numOfProductInStore <= 0) { 
     [self fetchFeed:@""]; 
    } 
    [self.refreshControl endRefreshing]; 
} 

所以基本上我声明refreshControl为类变量。正如尼尔提到的,我在方法-(void)refreshCollectionAction的末尾添加了[self.refreshControl endRefreshing]