Ios 当以程序方式调用UIRefreshControl时,UIRefreshControl不工作
我在我的Ios 当以程序方式调用UIRefreshControl时,UIRefreshControl不工作,ios,pull-to-refresh,uirefreshcontrol,Ios,Pull To Refresh,Uirefreshcontrol,我在我的ViewController中有一个UIRefreshControl和一个refreshView方法来处理“拉入刷新”事件。它在实际拖动时工作得非常好,但是当我在代码中调用[refresh beginRefreshing]时,它只显示刷新动画,而不调用refreshView方法 下面是在viewDidload中初始化刷新控件的代码: UIRefreshControl *refresh = [[UIRefreshControl alloc] init]; refresh.attribute
ViewController
中有一个UIRefreshControl
和一个refreshView
方法来处理“拉入刷新”事件。它在实际拖动时工作得非常好,但是当我在代码中调用[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;
试试这个
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];
根据我对文件的理解: 通知控件已启动刷新操作 以编程方式。。。当外部事件发生时调用此方法 source触发表的编程刷新 我认为它不用于启动刷新操作,而只是用于更新当前正在刷新的刷新控件状态,从而使刷新控件旋转。这样做的目的是避免用户拉动表视图,并在其仍在刷新时再次触发刷新操作
因此,您应该自己调用refreshView:方法。只需异步调用beginRefreshing即可
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
dispatch_async(dispatch_get_main_queue(), ^{
[refreshControl beginRefreshing];
});
//...
}
你的
viewDidLoad
代码与我的代码没有区别。方法refreshMyTableView
仍将不会在[refresh beginRefreshing]
上调用。请尝试在结束操作时删除“:”@selector(refreshView:)