UITableView UIRefreshControl 第一次不显示它的视图 [英] UITableView UIRefreshControl Does Not Show Its View The First Time

查看:50
本文介绍了UITableView UIRefreshControl 第一次不显示它的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 UITableView 的项目中添加了 UIRefreshControl 的功能.该应用程序通过从 Web 服务获取条目到 tableview 来工作.下面是我用来添加 UIRefreshControl 的代码:

I have added the functionality of UIRefreshControl in my project that uses a UITableView. The app works by fetching entries from a web service to a tableview. Below is the code i have used to add UIRefreshControl:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    refreshControl.tintColor = [UIColor grayColor];
    refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Updating New Entries"];
    [refreshControl addTarget:self action:@selector(pullToRefresh) forControlEvents:UIControlEventValueChanged];
    self.refreshControl = refreshControl;

    [self pullToRefresh];    
}

- (void) pullToRefresh
{
    counter = 1;
    [self fetchEntriesNew:counter]; // My code for updating table view

    [self performSelector:@selector(updateTable) withObject:nil afterDelay:2];
}

- (void)updateTable
{
    [self.tableView reloadData];
    [self.refreshControl endRefreshing];
}

现在,如果我拉动刷新,它会通过添加新条目(如果有)来刷新,并在 tableview 顶部显示以下视图:

Now if i pull to refresh, it refreshes by adding new entries if there are any and shows me the following view on top of the tableview:

除了第一次启动或打开应用程序时,一切都很好,它没有显示我在上图中显示的视图,尽管它刷新了表视图.我希望它每次刷新时都显示刷新控制视图.谁能指出我做错了什么?谢谢!

Everything works great except when the app is launched or opened for the very first time, it does not show the view that i have showed in the above image, although it does refreshes the tableview. I want it to show the refresh control view every time it refreshes it. Can anyone point out what i am doing wrong? Thanks!

更新:我添加了 [self refreshControl beginRefreshing] 并且 UIRefreshControl 的微调视图现在显示但它在 tableview 的第一个条目之上.谁能指出如何纠正它?

UPDATE: I have added [self refreshControl beginRefreshing] and the UIRefreshControl's spinner view is now showing but its above the first entry of the tableview. Can anyone point out how to correct it?

推荐答案

这个问题真的困扰了我一段时间.我发现4英寸的iOS设备没有这个问题,但3.5英寸的设备有.

This problem had really puzzled me for a while.I found that 4-inch iOS devices don't have this problem, but 3.5-inch devices do.

我试图找出refreshControl第一次开始刷新本身和我操作拉手势时的区别.这是拉操作.

I tried to find out the differences between the first time that the refreshControl beginRefreshing itself and when I operated a pull gesture.It's the pull operation.

我查看了苹果关于 UIRefreshControl 的文档.它说 控件不会直接启动刷新操作.相反,它会在应该发生刷新操作时发送 UIControlEventValueChanged 事件.

And I checked Apple's document on UIRefreshControl.It says The control does not initiate the refresh operation directly. Instead, it sends the UIControlEventValueChanged event when a refresh operation should occur.

所以我想也许我可以添加一些东西来模拟拉动手势来触发 refreshControl 的显示.

So I thought maybe I could add something to simulate a pull gesture to trigger refreshControl's showing.

[yourScrollView(or tableView) setContentOffset:CGPointMake(0.0f, -60.0f)
                                      animated:YES];
[yourRefreshControl beginRefreshing];

有效!

PS. UIRefreshControl 也适用于 UIScrollView.[yourScrollView addSubview:yourRefreshControl] 正常工作.

PS. UIRefreshControl works with UIScrollView, too. [yourScrollView addSubview:yourRefreshControl] just works.

这篇关于UITableView UIRefreshControl 第一次不显示它的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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