UIRefreshControl - iOS 7中的Pull to Refresh [英] UIRefreshControl - Pull To Refresh in iOS 7

查看:72
本文介绍了UIRefreshControl - iOS 7中的Pull to Refresh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在桌面视图中获得iOS 7上的pull to refresh功能。在我的 viewDidLoad 中,我有:

I'm trying to get the pull to refresh feature on iOS 7 in my Table View. In my viewDidLoad, I have:

refreshControl = [[UIRefreshControl alloc] init];
[self.mytableView setContentOffset:CGPointMake(0, refreshControl.frame.size.height) animated:YES];
[refreshControl beginRefreshing];
[refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged];

然后我运行:

-(void)refreshTable {
    [self.mytableView reloadData];
    [refreshControl endRefreshing];
}

在iOS 6上,这意味着当你向下拉表格视图时,它会显示一个圆形箭头,当你拉动时它会伸展开来,并且在拉得足够远之后,它会刷新。现在,我看不到圆形箭头。我缺少什么?

On iOS 6, this would mean that as you pull down on the table view, it would show the circular arrow that would get stretched out as you pull, and after pulled far enough, it would refresh. Right now, I see no circular arrow. What am I missing?

推荐答案

您不必显式设置框架或启动 UIRefreshControl 。如果它是 UITableView UICollectionView ,它应该像魅力本身一样工作。你确实需要停止它。

You do not have to explicitly set frame or start UIRefreshControl. If it is a UITableView or UICollectionView, it should work like a charm by itself. You do need to stop it though.

以下是你的代码的样子:

Here is how you code should look like:

- (void)viewDidLoad {
    [super viewDidLoad];
    refreshControl = [[UIRefreshControl alloc]init];
    [self.mytableView addSubview:refreshControl];
    [refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged];
}

refreshTable 中功能,您需要在刷新数据后停止它。以下是它的样子:

In your refreshTable function, you need to stop it when you are done refreshing your data. Here is how it is going to look like:

- (void)refreshTable {
    //TODO: refresh your data
    [refreshControl endRefreshing];
    [self.mytableView reloadData];
}

请注意,如果要异步刷新数据,则需要移动 endRefreshing reloadData 调用完成处理程序。

Please note that if you are refreshing your data asynchronously then you need to move endRefreshing and reloadData calls to your completion handler.

这篇关于UIRefreshControl - iOS 7中的Pull to Refresh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆