ios - UIRefreshControl 在 UITableViewController 中的位置错误

标签 ios objective-c uitableview uirefreshcontrol

我发现 UIRefreshControl 有很多问题,我的 UITableViewController 也有问题。问题发生得如此随机,此后我无法弄清楚为什么会发生或如何发生。

问题是,有时当您在 tableView 上向下滚动时,UIRefreshControl 出现在错误的位置,看起来像是在 tableView 本身的上方/顶部。我附上了问题的屏幕截图,以及我用于添加 UIRefreshControl 的代码及其刷新方法。

感谢您提供的任何帮助!

enter image description here

- (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/

相关文章:

ios - tableview 图像上的视差,使用自动布局

objective-c - iOS 上 native 代码中最快的 Apple 风格翻转计数器

ios - LaunchScreen 未显示在任何设备和项目上

iphone - 在 Objective - C 中使用 C++ 类

ios - UITableview 滚动顶部然后执行操作方法

ios - 如何在 iOS 7 中滚动到 UITableView 的顶部

ios - 以编程方式创建 UICollectionView

ios - 如何在适用于 iOS 的 Google Places Autocomplete 上保存最近的搜索?

ios - iPhone中的UiWebview根据内容大小调整大小

ios - 如何在 Swift 中删除 UITableView 中的行