我在实现UIRefreshControl时遇到问题-因为当您下拉菜单时,"blob"工作正常,刷新微调器工作正常,但是tableView在刷新时不会向上滚动到微调器.取而代之的是,它会一直停留到刷新完成之前的位置,然后返回到屏幕顶部
I'm having a problem implementing UIRefreshControl - in that when you pull down, the 'blob' works perfectly fine and the refresh spinner works fine, but the tableView doesn't scroll up to the spinner whilst refreshing. Instead, it stays where it was until the refreshing is complete, at which point it returns to the top of the screen
执行刷新的代码是:
- (void)viewDidLoad { self.refreshControl = [[UIRefreshControl alloc] init]; [self.refreshControl addTarget:self action:@selector(refreshView:)forControlEvents:UIControlEventValueChanged]; } - (void)refreshView:(UIRefreshControl *)refresh { dispatch_async(dispatch_get_main_queue(), ^{ (...code to get new data here...) [self.refreshControl endRefreshing]; } }我发现,如果没有dispatch_async,即使刷新微调器也不起作用-并且被下拉的位看起来只是白色
I found that without dispatch_async, even the refresh spinner doesn't work - and the bit that was pulled down appears just white
有人知道我可能做错了什么吗?我发现的所有实现示例似乎都与我正在做的事情相符,并且我在API文档中没有发现任何暗示我遗漏任何东西的东西
Does anyone have any clues what I could be doing wrong? All implementation examples I've found seems to match what I'm doing, and I haven't found anything in the API docs that suggest I'm missing anything out
推荐答案您可以更改为关注
- (void)refreshView:(UIRefreshControl *)refresh { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // (...code to get new data here...) dispatch_async(dispatch_get_main_queue(), ^{ //any UI refresh [self.refreshControl endRefreshing]; }); }); }-refreshView:将在主线程上被调用,并且所有UI更新都在使用主线程.因此,如果将主线程用于代码以获取新数据",它将卡住"
-refreshView: will get called on the main thread, and all UI updates are using the main thread. So if you use the main thread for "code to get new data" it will "stuck"
更多推荐
UIRefreshControl:刷新时,UITableView被“卡住"
发布评论