UIRefreshControl - 在 iOS 7 中下拉刷新 [英] UIRefreshControl - Pull To Refresh in iOS 7

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

问题描述

我正在尝试在我的表视图中获得 iOS 7 上的下拉刷新功能.在我的 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 上,这意味着当你下拉 table view 时,它会显示圆形箭头,当你拉的时候会被拉长,拉到足够远后,它会刷新.现在,我看不到圆形箭头.我错过了什么?

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.如果它是 UITableViewUICollectionView,它本身应该像一个魅力.不过你确实需要阻止它.

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.

您的代码应如下所示:

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

    if (@available(iOS 10.0, *)) {
        self.mytableView.refreshControl = refreshControl;
    } else {
        [self.mytableView addSubview:refreshControl];
    }
}

在您的 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];
}

请注意,如果您异步刷新数据,则需要将 endRefreshingreloadData 调用移动到完成处理程序.

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 中下拉刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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