8

我有一个方法UIRefreshControl来处理“拉刷新”事件。实际拉动时它工作得很好,但是当我调用代码时,它只显示刷新动画但不调用该方法。ViewControllerrefreshView[refresh beginRefreshing]refreshView

下面是初始化刷新控制的代码viewDidload

UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
[refresh addTarget:self
            action:@selector(refreshView:)
  forControlEvents:UIControlEventValueChanged];
self.refreshControl = refresh;
4

3 回答 3

14

根据我对文档的理解:http: //developer.apple.com/library/ios/#documentation/uikit/reference/UIRefreshControl_class/Reference/Reference.html

告诉控件以编程方式启动了刷新操作。...当外部事件源触发表的编程刷新时调用此方法。

我认为它不是用来启动刷新操作,而只是用于更新它当前正在刷新的刷新控制状态,它会使刷新控制旋转。目的是避免用户拉动表格视图并在它仍在刷新时再次触发刷新操作。

所以你应该自己调用 refreshView: 方法。

于 2013-05-23T16:11:49.017 回答
0

只需异步调用 beginRefreshing。

- (void)viewDidLoad {
   [super viewDidLoad];
   // Do any additional setup after loading the view.

   dispatch_async(dispatch_get_main_queue(), ^{
       [refreshControl beginRefreshing];
   });
   //...
}
于 2016-11-21T07:14:19.993 回答
-1

试试这个

ViewDidLoad

//initialise the refresh controller
refreshControl = [[UIRefreshControl alloc] init];
//set the title for pull request
refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"pull to Refresh"];
//call he refresh function
[refreshControl addTarget:self action:@selector(refreshMyTableView)
         forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;

方法

-(void)refreshMyTableView{

    //set the title while refreshing
    refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing the TableView"];
    //set the date and time of refreshing
    NSDateFormatter *formattedDate = [[NSDateFormatter alloc]init];
    [formattedDate setDateFormat:@"MMM d, h:mm a"];
    NSString *lastupdated = [NSString stringWithFormat:@"Last Updated on %@",[formattedDate stringFromDate:[NSDate date]]];
    refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:lastupdated];
    //end the refreshing

}

阻止它

[refreshControl endRefreshing];
于 2013-05-23T15:53:59.293 回答