我发现 UIRefreshControl 有很多问题,我的 UITableViewController 也有问题。问题发生得如此随机,此后我无法弄清楚为什么会发生或如何发生。
问题是,有时当您在 tableView 上向下滚动时,UIRefreshControl 出现在错误的位置,看起来像是在 tableView 本身的上方/顶部。我附上了问题的屏幕截图,以及我用于添加 UIRefreshControl 的代码及其刷新方法。
感谢您提供的任何帮助!
- (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;
}
最佳答案
这是 iOS7 的一个已知错误;有时刷新控件被错误地放在 View 层次结构的前面而不是后面。您可以通过在布局后将其发送回后台来解决部分问题:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self.refreshControl.superview sendSubviewToBack:self.refreshControl];
}
动画仍然会不完美,但至少它仍然在表格 View 下方。请开个bug report with Apple对于这个问题。
此外,如另一个答案所述,您不应该自己将刷新控件添加到 View 层次结构中。 TableView Controller 会为你做这件事。但这不是这里的问题。
Swift 版本
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
refreshControl?.superview?.sendSubview(toBack: refreshControl!)
}
关于ios - UIRefreshControl 在 UITableViewController 中的位置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21337534/