【问题标题】:Pulltorefresh works only once not multiple timesPulltorefresh 只工作一次而不是多次
【发布时间】:2016-09-07 00:39:39
【问题描述】:

我有一个带有原型单元格的表格视图。

我的 viewDidLoad 方法中有以下代码,

_refreshControl = [[UIRefreshControl alloc]init];

[_refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged];
UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = _tblView;
tableViewController.refreshControl = _refreshControl;

以下是我的 refreshData 方法....

 -(void)refreshData
{
    [_request getApproveStatutoryMapping];
    UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = _tblView;
[_tblView reloadData];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d, h:mm a"];
NSString *title = [NSString stringWithFormat:@"Last update: %@", [formatter stringFromDate:[NSDate date]]];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
                                                            forKey:NSForegroundColorAttributeName];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
tableViewController.refreshControl.attributedTitle = attributedTitle;

[tableViewController.refreshControl endRefreshing];

}

问题是

  1. attributedTitle 不可见
  2. 拉动刷新只能工作一次,如果我再次拉动它,它就不起作用。为什么会这样?

【问题讨论】:

    标签: ios objective-c uitableview pull-to-refresh uirefreshcontrol


    【解决方案1】:

    您将像 UIViewController 的属性一样定义 UITableViewController *tableViewController

    refreshData方法中删除行

    UITableViewController *tableViewController = [[UITableViewController alloc] init];
    tableViewController.tableView = _tblView;
    

    方法 endRefreshing 必须在刷新数据后调用,而不是在开始刷新时调用,否则您将在不到一秒的时间内看到预加载器,而无需等待更新

    这里

    NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
                                                                forKey:NSForegroundColorAttributeName];
    

    您将刷新标题的颜色定义为白色,如果背景为白色,您将永远看不到标题

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,刷新的拉动只能工作一次。经过一番努力,我得到了一个解决方案,即在将数据加载到 tableview 之前,我们需要停止拉取刷新。

      refreshControl.endRefreshing()
      

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 2020-11-12
        • 1970-01-01
        • 2021-08-25
        • 2011-11-21
        • 1970-01-01
        • 1970-01-01
        • 2013-10-13
        • 1970-01-01
        • 2017-01-06
        相关资源
        最近更新 更多