UIRefreshControl:刷新时,UITableView被“卡住"

编程入门 行业动态 更新时间:2024-10-23 11:22:08
本文介绍了UIRefreshControl:刷新时,UITableView被“卡住"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在实现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被“卡住"

本文发布于:2023-11-23 18:34:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622472.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UIRefreshControl   UITableView   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!