UIRefreshControl:刷新时,UITableView被“卡住" [英] UIRefreshControl: UITableView 'stuck' while refreshing

查看:118
本文介绍了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被“卡住"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆