我为UIRefreshControl
实施了UICollectionView
,以便用户可以提取以刷新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服务请求数据。我已经确认网络服务仍然有效。
答案 0 :(得分:4)
[self.refreshControl endRefreshing];
在任何刷新操作结束时调用此方法(无论是以编程方式还是由用户方式启动),以将刷新控件返回到其默认状态。如果刷新控件至少部分可见,则调用此方法也会隐藏它。如果还启用了动画,则使用动画隐藏控件。 UIRefreshControl Class Reference
答案 1 :(得分: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声明为类变量。正如Neil所说,我在方法[self.refreshControl endRefreshing]
的末尾添加了-(void)refreshCollectionAction
。