gpt4 book ai didi

ios - UIRefreshControl - 当 UITableViewController 在 UINavigationController 内时,beginRefreshing 不起作用

转载 作者:IT老高 更新时间:2023-10-28 12:20:18 25 4
gpt4 key购买 nike

我在我的 UITableViewController(在 UINavigationController 内)中设置了一个 UIRefreshControl,它按预期工作(即下拉触发正确的事件)。但是,如果我以编程方式调用刷新控件上的 beginRefreshing 实例方法,例如:

[self.refreshControl beginRefreshing];

什么都没有发生。它应该动画下来并显示微调器。当我在刷新后调用 endRefreshing 方法时,它可以正常工作。

我用这种行为创建了一个基本原型(prototype)项目,当我的 UITableViewController 直接添加到应用程序委托(delegate)的 Root View Controller 时它可以正常工作,例如:

self.viewController = tableViewController;
self.window.rootViewController = self.viewController;

但如果我先将 tableViewController 添加到 UINavigationController,然后将导航 Controller 添加为 rootViewController,则 beginRefreshing 方法不再起作用.例如

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
self.viewController = navController;
self.window.rootViewController = self.viewController;

我的感觉是这与导航 Controller 中的嵌套 View 层次结构与刷新控件不兼容有关 - 有什么建议吗?

谢谢

最佳答案

如果您开始以编程方式刷新,您似乎必须自己滚动表格 View ,例如,通过更改 contentoffset

[self.tableView setContentOffset:CGPointMake(0, -self.refreshControl.frame.size.height) animated:YES];

我猜这是因为当用户在表格 View 的中间/底部时滚动到刷新控件可能是不可取的?

@muhasturk 的 Swift 2.2 版本

self.tableView.setContentOffset(CGPoint(x: 0, y: -refreshControl.frame.size.height), animated: true)

简而言之,为了保持这个便携性,添加这个扩展

UIRefreshControl+ProgramaticallyBeginRefresh.swift

extension UIRefreshControl {
func programaticallyBeginRefreshing(in tableView: UITableView) {
beginRefreshing()
let offsetPoint = CGPoint.init(x: 0, y: -frame.size.height)
tableView.setContentOffset(offsetPoint, animated: true)
}
}

关于ios - UIRefreshControl - 当 UITableViewController 在 UINavigationController 内时,beginRefreshing 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14718850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com