UIRefreshControl在UITableViewController中位置错误 [英] UIRefreshControl is in wrong position in UITableViewController

查看:137
本文介绍了UIRefreshControl在UITableViewController中位置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIRefreshControl上看到了很多问题,而且我的UITableViewController也遇到了问题。问题是如此随机发生,从此我无法弄清楚为什么或如何发生。

I've seen quite a few problems with UIRefreshControl, and I'm having a problem as well with my UITableViewController. The problem occurs so randomly and henceforth I cannot figure out why or how it happens.

问题是,有时当你向下滚动tableView时,UIRefreshControl出现在错误的地方,以及看上面/在tableView本身之上的东西。我附上了问题的截图,我的代码也用于添加UIRefreshControl和它的刷新方法。

The problem is that sometimes when you scroll down on the tableView, the UIRefreshControl appears in the wrong place, and what seems like above/on top of the tableView itself. I'm attaching a screenshot of what the problem looks like, and also my code used to add the UIRefreshControl and it's refreshing method as well.

我感谢任何提供的帮助!

I appreciate any help offered!

- (void)viewDidLoad
{
    self.refreshControl = [[UIRefreshControl alloc] init];

    [self.refreshControl addTarget:self action:@selector(refreshing:) forControlEvents:UIControlEventValueChanged];

    [self.tableView addSubview:self.refreshControl];

    self.tableView.tableFooterView = [[UIView alloc] init];
}

- (void)refreshing:(UIRefreshControl*)refreshControl
{
    [refreshControl beginRefreshing];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    [refreshControl endRefreshing];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
 }


推荐答案

这是一个已知的错误IOS 7;有时刷新控件被错误地放在视图层次结构的前面而不是后面。您可以通过在布局后将其发送回来解决部分问题:

This is a known bug with iOS7; sometimes the refresh control is put incorrectly in the front of the view hierarchy instead of back. You can counter part of the problem by sending it to back after layout:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    [self.refreshControl.superview sendSubviewToBack:self.refreshControl];
}

动画仍然不完美,但至少它仍然低于桌子视图。请针对此问题打开与Apple的错误报告

Animation will still be imperfect, but at least it will still be below the table view. Please open a bug report with Apple for this issue.

另外,如另一个答案所述,您不应自行将刷新控件添加到视图层次结构中。表视图控制器将为您执行此操作。但这不是问题。

Also, as stated in another answer, you should not add the refresh control to the view hierarchy yourself. The table view controller will do that for you. But that is not the issue here.

Swift版本

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    refreshControl?.superview?.sendSubview(toBack: refreshControl!)
}

这篇关于UIRefreshControl在UITableViewController中位置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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