<i id='qlf7P'><tr id='qlf7P'><dt id='qlf7P'><q id='qlf7P'><span id='qlf7P'><b id='qlf7P'><form id='qlf7P'><ins id='qlf7P'></ins><ul id='qlf7P'></ul><sub id='qlf7P'></sub></form><legend id='qlf7P'></legend><bdo id='qlf7P'><pre id='qlf7P'><center id='qlf7P'></center></pre></bdo></b><th id='qlf7P'></th></span></q></dt></tr></i><div id='qlf7P'><tfoot id='qlf7P'></tfoot><dl id='qlf7P'><fieldset id='qlf7P'></fieldset></dl></div>
    1. <small id='qlf7P'></small><noframes id='qlf7P'>

      1. <tfoot id='qlf7P'></tfoot>

          <bdo id='qlf7P'></bdo><ul id='qlf7P'></ul>
        <legend id='qlf7P'><style id='qlf7P'><dir id='qlf7P'><q id='qlf7P'></q></dir></style></legend>

        UIRefreshControl - 当 UITableViewController 在 UINavigationCon

        时间:2023-05-16
      2. <legend id='caIGD'><style id='caIGD'><dir id='caIGD'><q id='caIGD'></q></dir></style></legend>

        <tfoot id='caIGD'></tfoot>

          <i id='caIGD'><tr id='caIGD'><dt id='caIGD'><q id='caIGD'><span id='caIGD'><b id='caIGD'><form id='caIGD'><ins id='caIGD'></ins><ul id='caIGD'></ul><sub id='caIGD'></sub></form><legend id='caIGD'></legend><bdo id='caIGD'><pre id='caIGD'><center id='caIGD'></center></pre></bdo></b><th id='caIGD'></th></span></q></dt></tr></i><div id='caIGD'><tfoot id='caIGD'></tfoot><dl id='caIGD'><fieldset id='caIGD'></fieldset></dl></div>
            <bdo id='caIGD'></bdo><ul id='caIGD'></ul>
              <tbody id='caIGD'></tbody>

              1. <small id='caIGD'></small><noframes id='caIGD'>

                  本文介绍了UIRefreshControl - 当 UITableViewController 在 UINavigationController 内时,beginRefreshing 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

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

                  I've setup a UIRefreshControl in my UITableViewController (which is inside a UINavigationController) and it works as expected (i.e. pull down fires the correct event). However, if I programmatically invoke the beginRefreshing instance method on the refresh control like:

                  [self.refreshControl beginRefreshing];
                  

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

                  Nothing happens. It should animate down and show the spinner. The endRefreshing method works properly when I call that after the refresh.

                  我用这种行为创建了一个基本原型项目,当我的 UITableViewController 直接添加到应用程序委托的根视图控制器时它可以正常工作,例如:

                  I whipped up a basic prototype project with this behavior and it works properly when my UITableViewController is added directly to application delegate's root view controller, e.g:

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

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

                  But if I add the tableViewController to a UINavigationController first, then add the navigation controller as the rootViewController, the beginRefreshing method no longer works. E.g.

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

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

                  My feeling is this has something to do with the nested view hierarchies within the navigation controller not playing nice with the refresher control - any suggestions?

                  谢谢

                  推荐答案

                  似乎如果你开始以编程方式刷新,你必须自己滚动表格视图,比如通过改变 contentoffset

                  It seems that if you start refreshing programmatically, you have to scroll the table view yourself, say, by changing contentoffset

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

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

                  I would guess the reason for this is that it could be undesirable to scroll to the refresh control when user is in the middle/bottom of the table view?

                  @muhasturk 的 Swift 2.2 版本

                  Swift 2.2 version by @muhasturk

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

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

                  In a nutshell, to keep this portable add this extension

                  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)        
                      }
                  }
                  

                  这篇关于UIRefreshControl - 当 UITableViewController 在 UINavigationController 内时,beginRefreshing 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UINavigationController“后退按钮"自定义文本? 下一篇:设置 leftBarButtonItem 后如何在 UINavigationController 中启用后退/左滑手势?

                  相关文章

                    <bdo id='Q2ryt'></bdo><ul id='Q2ryt'></ul>

                  <small id='Q2ryt'></small><noframes id='Q2ryt'>

                  <legend id='Q2ryt'><style id='Q2ryt'><dir id='Q2ryt'><q id='Q2ryt'></q></dir></style></legend>
                  1. <tfoot id='Q2ryt'></tfoot>

                    1. <i id='Q2ryt'><tr id='Q2ryt'><dt id='Q2ryt'><q id='Q2ryt'><span id='Q2ryt'><b id='Q2ryt'><form id='Q2ryt'><ins id='Q2ryt'></ins><ul id='Q2ryt'></ul><sub id='Q2ryt'></sub></form><legend id='Q2ryt'></legend><bdo id='Q2ryt'><pre id='Q2ryt'><center id='Q2ryt'></center></pre></bdo></b><th id='Q2ryt'></th></span></q></dt></tr></i><div id='Q2ryt'><tfoot id='Q2ryt'></tfoot><dl id='Q2ryt'><fieldset id='Q2ryt'></fieldset></dl></div>