【问题标题】:UIRefreshControl loading icon still loadingUIRefreshControl 加载图标仍在加载
【发布时间】:2014-04-19 14:13:44
【问题描述】:

我为UICollectionView 实现了一个UIRefreshControl,以便用户可以拉动以刷新UICollectionView 中的内容。我正在 iPad 模拟器上进行测试。

在第一次尝试时,我能够提取并刷新内容。但是,我注意到加载图标仍在加载并且不会停止。在我第二次尝试加载图标仍然显示时,我拉动刷新,但它无法调用我的选择器(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 服务请求数据。我已验证该网络服务仍然有效。

【问题讨论】:

    标签: ios uicollectionview uirefreshcontrol


    【解决方案1】:
    [self.refreshControl endRefreshing];
    

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

    【讨论】:

    • Добрый день。来自新加坡。非常感谢您。它现在正在工作。我会在一段时间内发布我的解决方案。
    【解决方案2】:
    @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]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-07
      • 1970-01-01
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多